我的 pdo 语法有什么问题?
what is wrong with my pdo syntax?
我正在尝试执行如下定义的 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'));
但是无论我怎样尝试returns出现如下错误
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
我看不出我的语法有什么问题导致了这种情况,非常感谢任何反馈。
我希望语法如下所示:
UPDATE users
SET email = :email,
name = :name
WHERE userId = :userId;
我正在尝试执行如下定义的 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'));
但是无论我怎样尝试returns出现如下错误
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
我看不出我的语法有什么问题导致了这种情况,非常感谢任何反馈。
我希望语法如下所示:
UPDATE users
SET email = :email,
name = :name
WHERE userId = :userId;