我正在尝试使用以下查询更新我的数据库:
$sth = "UPDATE rpacks SET rpacks_location VALUES (:location) WHERE rpacks_id = (:id)";
$q = $conn->prepare($sth);
$q->execute(array(':location'=>$location, ':id'=>$id));
但我收到此错误
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'VALUES ('test') WHERE rpacks_id = ('2')' at line 1' in
答案 0 :(得分:9)
您的update
查询中存在错误,因为您使用了insert
查询语法。
这是正确的查询:
$sth = "UPDATE rpacks SET rpacks_location = :location WHERE rpacks_id = :id";
答案 1 :(得分:3)
更改为:
$sth = "UPDATE rpacks SET rpacks_location = :location WHERE rpacks_id = :id";