gpt4 book ai didi

php - PDO 错误 :SQLSTATE[42000]: Syntax error or access violation: 1064

转载 作者:行者123 更新时间:2023-11-29 03:01:52 25 4
gpt4 key购买 nike

请帮我解决以下错误:

ERROR: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 ':username, oncall_area = :oncall_area, oncall_month = :oncall_mo' at line 2

我的代码是:

try {
$db = new PDO("mysql:host=$server;dbname=$dbname;charset=utf8", $dbuser, $dbpass);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$sql = "
UPDATE `oncall_users`
SET `username` = :username,
`oncall_area` = :oncall_area,
`oncall_month` = :oncall_month,
`oncall_year` = :oncall_year,
`oncall_day` = :oncall_day,
`order` = :order,
`mobile` = :mobile,
`email` = :email,
`ext` = :ext,
WHERE `id` = :id";

$update = $db->exec($sql);

$update->bindParam(':username', $username, PDO::PARAM_STR);
$update->bindParam(':oncall_area', $oncall_area);
$update->bindParam(':oncall_month', $oncall_month);
$update->bindParam(':oncall_year', $oncall_year);
$update->bindParam(':oncall_day', $oncall_day);
$update->bindParam(':order', $order);
$update->bindParam(':email', $email);
$update->bindParam(':mobile', $mobile);
$update->bindParam(':ext', $ext);
$update->bindParam(':id', $id);

$count = $update->execute();
$db = null; // Disconnect
}
catch(PDOException $e) {
echo "ERROR:" . $e->getMessage();
}

最佳答案

这里多了一个逗号:

`ext` = :ext,

替换为:

`ext` = :ext

这就是导致您出现问题的原因。

关于php - PDO 错误 :SQLSTATE[42000]: Syntax error or access violation: 1064,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22375894/

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