Php 查询工作时跟踪PDOException泛型执行选项
我有一段非常直接的代码。我使用AJAX和PHP更新MySQ表,并进行了正确的更改,但每次执行时都会出现以下错误:Php 查询工作时跟踪PDOException泛型执行选项,php,mysql,ajax,pdo,Php,Mysql,Ajax,Pdo,我有一段非常直接的代码。我使用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/c
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;
};
?>
我是不是在这里找不到证据,或者是处理不当?
thx使函数返回$stmt而不是fetchall()结果您试图在
更新
查询中使用fetchall()
,该查询不会返回任何可获取的结果。要使用fetchall(),查询必须是选择…
,然后您就做错了。我希望您也成功地删除了fetchall()调用
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;
}