在第1行'group ='1'WHERE id = 6'附近的MySQL语法错误

时间:2022-06-19 00:22:28

I have a pretty simple task I want to perform, when I run the code one way it's fine, if I run it another way Fatal error: Uncaught exception 'Exception'...

我有一个非常简单的任务我想要执行,当我以一种方式运行代码它没关系,如果我以另一种方式运行它致命错误:未捕获异常'异常'...

Works

if (Input::get('userid')) {

    $user_id = Input::get('userid');

    $user->find($user_id);

    $name = $user->data()->first_name;


    if ($user->data()->active == 1) {

        $user->update(array(
            'active' => 0
        ));

        Session::flash('userboard', $name.' Deactivated');
        Redirect::to('admin.php');

    } else {

        $user->update(array(
            'active' => 1
        ));

        Session::flash('userboard', $name.' Activated');
        Redirect::to('admin.php');

    }

}

Doesn't Work

if (Input::get('adminid')) {

    $user_id = Input::get('adminid');

    $user->find($user_id);

    $name = $user->data()->first_name;

    if ($user->data()->active == 1) {

        $user->update(array(
            'group' => 1
        ));

        Session::flash('userboard', $name.' Deactivated');
        Redirect::to('admin.php');

    } else {

        $user->update(array(
            'group' => 2
        ));

        Session::flash('userboard', $name.' Activated');
        Redirect::to('admin.php');

    }

}

No matter which way I change it around I can't update the group. They are both int(11) in MySQL. I'm almost wondering if I need to delete the column and re add it? This group value is used for setting user permissions if that's of any help.

无论我改变它的方式,我无法更新组。它们都是MySQL中的int(11)。我几乎想知道是否需要删除该列并重新添加它?如果有任何帮助,此组值用于设置用户权限。


PDO errorInfo

Array ( [0] => 42000 [1] => 1064 [2] => 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 'group = '1' WHERE id = 6' at line 1 )

数组([0] => 42000 [1] => 1064 [2] =>您的SQL语法有错误;请查看与您的MySQL服务器版本对应的手册,以便在'group ='附近使用正确的语法1第1行'WHERE id = 6')

1 个解决方案

#1


Your framework, or class, isn't putting ticks around the column. Group is a reserved keyword in MySQL (and probably every DBMS), so the column must be quoted with backticks: `group`

您的框架或类不会在列中添加标记。 Group是MySQL中的保留关键字(可能是每个DBMS),因此该列必须用反引号引用:`group`

#1


Your framework, or class, isn't putting ticks around the column. Group is a reserved keyword in MySQL (and probably every DBMS), so the column must be quoted with backticks: `group`

您的框架或类不会在列中添加标记。 Group是MySQL中的保留关键字(可能是每个DBMS),因此该列必须用反引号引用:`group`