php – PDO UPDATE:语法错误或访问冲突

前端之家收集整理的这篇文章主要介绍了php – PDO UPDATE:语法错误或访问冲突前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我是PDO的新手,编写更新查询
$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);

得到:

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 ‘(uname =
‘rahman@abc.def’,role = ‘2’,fname = ‘A full Name’,email = ‘rahm’
at line 1

谁能告诉我我的代码有什么问题?

这是我的表结构:

删除SET部分周围的括号:
$sql  =  "UPDATE `users` 
          SET  `uname` = :uname,`looking_for` = :looking 
         WHERE `id` = :id";

检查UPDATE syntax

UPDATE [LOW_PRIORITY] [IGNORE] table_reference
    SET col_name1={expr1|DEFAULT} [,col_name2={expr2|DEFAULT}] ...
    [WHERE where_condition]
    [ORDER BY ...]
    [LIMIT row_count]
原文链接:https://www.f2er.com/php/135061.html

猜你在找的PHP相关文章