PHP PDO更新预备语句

时间:2013-04-14 12:16:39

标签: php pdo

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

$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

2 个答案:

答案 0 :(得分:9)

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

这是正确的查询:

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

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

答案 1 :(得分:3)

更改为:

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