PDO error: “ SQLSTATE[HY000]: General error ” When updating database

夙愿已清 提交于 2019-12-17 02:30:23

问题


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.

Code:

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();
}

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.


回答1:


You do not use fetchAll(),as in

$result = $stmt->fetchAll();

with update or insert queries. Removing this statement should rectify the problem.




回答2:


Just to note, another possible reason for this error is if you make a second database call with the variable $stmt inside of an existing parent $stmt loop.

     $stmt = $conn->query($sql);

    while ($row = $stmt->fetch()) {  //second use of $stmt here inside loop


来源:https://stackoverflow.com/questions/12979510/pdo-error-sqlstatehy000-general-error-when-updating-database

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!