2

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 时必须有不同的方法来执行此操作。

4

2 回答 2

6

你错过了一个 SET

UPDATE alltimehighscores SET time = time + :time WHERE username = :username
于 2012-05-25T20:04:08.780 回答
1

SET不见了:

UPDATE alltimehighscores SET `time` = `time` + :time
WHERE username = :username
于 2012-05-25T20:04:26.613 回答