我不確定發生了什麼。我正嘗試使用掛起用戶的函數更新值爲0的'用戶'表。列名是'active',tinyint(1)的默認值爲0,我試着查詢'active = 0','active = false',active =!active','active = NOT active ',active ='DEFAULT',這些查詢都沒有返回錯誤,但沒有一個正在更新表格...我也嘗試過以多種方式綁定數值無濟於事...無法更新mysql列中的值
function suspendUser($id){
global $dbc;
$sus = $dbc->prepare("UPDATE users SET active = 0 WHERE user_id = :id");
$sus->bindParam(':id', $id, PDO::PARAM_INT);
$sus->execute();
if($sus->rowCount() > 0){
return true;
}
else{
return 'There was an error with your request.';
}
}
這是我的配置文件
try {
$dbc = new PDO("mysql:host=$db_host;dbname=$db_name;charset=utf8", $db_username, $db_password);
$dbc->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); }
catch(PDOException $e){
echo "Connection failed: " . $e->getMessage(); }
// create the error handler
function my_error_handler($e_number, $e_message, $e_file, $e_line, $e_vars){
global $debug, $contact_email;
$message = "An error occurred in script '$e_file' on line $e_line: $e_message";
$message .= print_r($e_vars, 1);
if($debug){
echo '<div class="error">'.$message.'</div>';
debug_print_backtrace();
}
else{
error_log($message, 1, $contact_email);
if(($e_number != 'E_NOTICE') && ($e_number < 2048)){
echo '<div class="error">A system error occurred. We apologize for the inconvenience.</div>';
}
}
}
set_error_handler('my_error_handler');
這是JavaScript函數
function suspendUser(uid){
$.ajax({ url: 'lib/user-edit.php',
data:{action: 'suspend', id: uid},
type:'post',
success: function(t){
$('#' + uid).prepend('<p>'+t+'<br>Sucessfully suspended</p>');
}
});
}
然後
if(isset($_POST['action'])){
$action = $_POST['action'];
}
if(isset($_POST['id'])){
$id = $_POST['id'];
}
if(isset($_POST['role'])){
$role = $_POST['role'];
}
else{
return 'There was an error with your request.';
}
// define the function to execute based on the posted action
if($action == 'change'){
changeRole($id);
}
if($action == 'delete'){
deleteUser($id);
}
if($action == 'suspend'){
suspendUser($id);
}
我已將此添加功能:
function suspendUser($id){
global $dbc;
$sus = $dbc->prepare("UPDATE users SET active = 0 WHERE user_id = :id");
$sus->bindParam(':id', $id, PDO::PARAM_INT);
$sus->execute();
if (!$dbc->execute()) {
$err = print_r($dbc->errorInfo());
return $err;
}
if($sus->rowCount() > 0){
$err = print_r($dbc->errorInfo());
return $err;
}
else{
$err = print_r($dbc->errorInfo());
return $err;
}
}
我仍然沒有得到錯誤。
獲取* actual *錯誤,讓我們知道那是什麼。像我說的那樣, –
....沒有錯誤。一切行爲都像查詢成功一樣。 – MAtkins
不,有錯誤,你只是不報告他們。 [PDO錯誤檢查](http://php.net/manual/en/pdo.error-handling.php) –