gpt4 book ai didi

php - 我的 pdo 语法有什么问题?

转载 作者:行者123 更新时间:2023-11-29 05:19:33 25 4
gpt4 key购买 nike

我正在尝试执行如下定义的 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

我看不出我的语法有什么问题导致了这种情况,非常感谢任何反馈。

最佳答案

我希望语法看起来像这样:

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

关于php - 我的 pdo 语法有什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27772954/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com