【发布时间】:2012-05-25 20:02:24
【问题描述】:
当我尝试执行以下查询时,我收到了错误 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 '= time + '1' WHERE username = 'admin-test'' at line 1:
try
{
$sth = $dbh->prepare("UPDATE alltimehighscores time = time + :time
WHERE username = :username");
$arr = array(
':username' => $username,
':time' => $time
);
$sth->execute($arr);
}
catch (PDOException $e)
{
echo $e->getMessage();
exit();
}
$time 和 $username 值是早先从 $_GET 分配的。 $dbh 也在上面分配,它工作正常,因为上面还有另一个查询可以正常执行。
查看错误消息,我可以看到 time 没有被更改为当前数据库值,因此我假设在使用 PDO 时必须有不同的方法。
【问题讨论】: