简体   繁体   中英

PDO ERROR:SQLSTATE[42000]: Syntax error or access violation: 1064

Help me with the error below please:

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

My code is:

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();
}

You have an additional comma here:

`ext` = :ext,

replace by:

`ext` = :ext

this is what's causing your issue.

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