简体   繁体   English

在UPDATE查询中绑定参数时,PDO异常

[英]PDO Exception when binding parameters in an UPDATE query

I have the following SQL UPDATE query using PDO and binding two parameters, but I get an error: 我有以下使用PDO和绑定两个参数的SQL UPDATE查询,但出现错误:

$updateSql = $con->prepare("UPDATE menu SET '".$field."' = :value WHERE 'id' = :idField");
$updateSql->execute(array(
    ':value' => $value,
    ':idField' => $id));

And the error is telling me: 错误告诉我:

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 Syntax error next to ''dish' = ? WHERE 'id' = ?' 

NOTE: The UPDATE is executed correctly, but the script stops running with the Fatal Error. 注意:UPDATE已正确执行,但脚本因致命错误而停止运行。

You enclosed the column name by single quotes. 您用单引号将列名引起来。 Remove single quotes. 删除单引号。

$updateSql = $con->prepare("UPDATE menu SET ".$field." = :value WHERE id = :idField");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM