我有一个非常简单的任务要执行,当我以一种方式运行代码时它很好,如果我以另一种方式运行它 fatal error :未捕获的异常“异常”...
有效
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');
}
}
不起作用
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');
}
}
无论我以何种方式改变它,我都无法更新组。它们在 MySQL 中都是 int(11)。我几乎想知道是否需要删除该列并重新添加它?如果有任何帮助,此组值用于设置用户权限。
PDO 错误信息
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 )
最佳答案
您的框架或类没有在列周围打勾。 Group 是 MySQL(可能每个 DBMS)中的保留关键字,因此该列必须用反引号引起来:`group`
关于php - 第 1 行 'group = ' 1' WHERE id = 6' 附近的 MySQL 语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30101091/