問題描述
我在使用 PDO 更新數據庫時遇到錯誤.我是 PDO 的新手,所以問題可能很小,我只是不明白.這個錯誤很有趣,命令運行良好,數據庫確實得到了更新.但它仍然向我返回一個錯誤.
I am getting an error when updating a database using PDO. I am new to PDO so maybe the problem is a small one and I just don't understand. Funny thing about the error, the command works fine and the database does actually get updated. But it still returns an error back at me.
代碼:
try {
$stmt = $pdo->prepare("UPDATE $page SET $section = :new_content WHERE $section = '$old_content'");
$stmt->execute(array(
'new_content' => $new_content
));
$result = $stmt->fetchAll();
echo "Database updated!";
}
catch(PDOException $e) {
echo 'ERROR UPDATING CONTENT: ' . $e->getMessage();
}
錯誤:錯誤更新內容:SQLSTATE[HY000]:一般錯誤
Error: ERROR UPDATING CONTENT: SQLSTATE[HY000]: General error
我真的不知道問題出在哪里,因為它非??斩?,而且我找不到任何有同樣問題的人.
I literally have no idea where the problem could be because its very vaque and I haven't been able to find anyone with the same problem.
推薦答案
你不使用 fetchAll(),如
You do not use fetchAll(),as in
$result = $stmt->fetchAll();
帶有更新或插入查詢.刪除此語句應該可以解決問題.
with update or insert queries. Removing this statement should rectify the problem.
這篇關于PDO 錯誤:"SQLSTATE[HY000]:一般錯誤更新數據庫時的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!