当我尝试执行以下查询时,我收到错误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时必须有不同的方法。
答案 0 :(得分:6)
你错过了一个SET
UPDATE alltimehighscores SET time = time + :time WHERE username = :username
答案 1 :(得分:1)
SET
缺失:
UPDATE alltimehighscores SET `time` = `time` + :time
WHERE username = :username