2

我正在尝试使用以下查询更新我的数据库:

$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

4

2 回答 2

10

您的查询中有错误,update因为您使用了insert查询语法。

这是正确的查询:

$sth = "UPDATE rpacks SET rpacks_location = :location WHERE rpacks_id = :id";

参考: http ://dev.mysql.com/doc/refman/5.0/en/update.html

于 2013-04-14T12:24:40.223 回答
4

改成:

$sth = "UPDATE rpacks SET rpacks_location = :location WHERE rpacks_id = :id";

于 2013-04-14T12:20:47.760 回答