我有这么简单的代码。我使用AJAX和PHP来更新MySQ表,并且发生了正确的更改,但每次执行时都会出现此错误:
PHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General error' in /var/www/html/rollcall/classes/class.user.php:176\nStack trace:\n#0 /var/www/html/rollcall/classes/class.user.php(176): PDOStatement->fetchAll(2)\n#1 /var/www/html/rollcall/appeal-handler.php(8): USER->appealIsRead('112')\n#2 {main}\n thrown in /var/www/html/rollcall/classes/class.user.php on line 176, referer: http://localhost/rollcall/views/notifications.php
现在journy在这个JS函数中开始:
function removeAppeal(appeal_id){
document.getElementById('an_'+appeal_id).style.display = "none";
jQuery.ajax({
url: '../appeal-handler.php',
type: 'POST',
data: { appealId: appeal_id },
complete: function(data, status)
{
if(status=='success')
{
alert('saved!');
}
}
});
};
并转移到这个PHP代码:
<?php
require_once("classes/class.user.php");
$auth_user = new USER();
$appeal_id = $_POST['appealId'];
if($auth_user->appealIsRead($appeal_id)){
return true;
};
?>
以执行此USER
方法结束:
public function appealIsRead($appeal_id){
$stmt = $this->conn->prepare("UPDATE appeals SET `read` = 1 WHERE `appeal_id` = :appeal_id");
$stmt->execute(array(':appeal_id' => $appeal_id));
$result = $stmt->fetchall(PDO::FETCH_ASSOC);
return $result;
}
这里是否缺少验证或某种不当处理? thx
答案 0 :(得分:1)
您尝试在fetchall()
查询中使用UPDATE
,不会返回任何可获取的结果。要使用fetchall(),查询必须是SELECT ...
答案 1 :(得分:0)
让你的函数返回$ stmt而不是fetchall()result