简体   繁体   中英

what is wrong with my pdo syntax?

I'm trying to execute a pdo update statement definded as follows:

 $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'));

But no matter what I try it returns the following 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 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

I can't see what is wrong with my syntax that is causing this any feedback much appreciated.

I would expect the syntax to look like:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM