我的pdo语法出了什么问题?

时间:2015-01-05 03:16:01

标签: php mysql pdo

我试图按照以下方式执行pdo更新语句:

 $sql = "UPDATE users SET (email,name) VALUES (:email,:name) WHERE userId = :userId";
 $result= $db->prepare($sql);
 $result->execute(array(':userId'=>21,':email'=>'test',':name'=>'testname'));

但无论我尝试什么,都会返回以下错误

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 MariaDB server version for the right syntax to use near '(email,name) VALUES ('test','testname') WHERE userId = '21'' at line 1' in /var/www/vhosts/tftest.co.uk/biggreensquare.co.uk/application/models/user_model.php:79

我无法看到我的语法错误导致任何反馈非常受欢迎。

1 个答案:

答案 0 :(得分:3)

我希望语法看起来像:

UPDATE users
    SET email = :email,
        name = :name
    WHERE userId = :userId;