Tôi mới trong PDO, viết một truy vấn cập nhật:PDO UPDATE: Cú pháp lỗi hoặc vi phạm truy cập
$sql = "UPDATE `users`
SET(`uname` = :uname,
`role` = :role,
`fname` = :fname,
`email` = :email,
`mobile1` = :mobile1,
`mobile2` = :mobile2,
`education` = :education,
`division` = :division,
`district` = :district,
`sub_district` = :sub_district,
`address` = :address,
`looking_for` = :looking)
WHERE `id` = :id";
//$sql = "UPDATE `users` SET(`uname`=?,`role`=?,`fname`=?,`email`=?,`mobile1`=?,`mobile2`=?,`education`=?,`division`=?,`district`=?,`sub_district`=?,`address`=?,`looking_for`=?) WHERE `id`=?";
$st = $conn->prepare($sql);
//$res['sql'] = $st->queryString;
$params = array(
':uname' => $uname,
':role' => $role,
':fname' => $fname,
':email' => $email,
':mobile1' => $mobile1,
':mobile2' => $mobile2,
':education' => $edu,
':division' => $division,
':district' => $district,
':sub_district' => $sub_district,
':address' => $address,
':looking' => $looking,
':id' => $id
);
//$res['params'] = $params;
$r = $st->execute($params);
Và nhận:
SQLSTATE [42000]: Cú pháp lỗi hoặc vi phạm truy cập: 1064 Bạn có một lỗi trong cú pháp SQL của mình; kiểm tra hướng dẫn tương ứng với phiên bản máy chủ MariaDB của bạn để có cú pháp đúng để sử dụng gần '(
uname
= ' [email protected] ',role
=' 2 ',fname
=' Tên đầy đủ ',
ai có thể cho tôi biết những gì sai trái trong mã của tôi
Dưới đây là cấu trúc bảng của tôi:?
Chân đế được sử dụng để truy vấn con https://dev.mysql.com/doc/refman/5.7/en/subqueries.html –