我编写了以下代码来使用whereColumn方法更新数据:
Ratings::whereColumn([['class_id', '=', $class_id], ['id', '=', $rating_id]])->update(['grade' => $grade, 'star' => $star, 'comment' => $comment]);
这会产生SQL错误:
SQLSTATE[42S22]: Column not found: 1054 Unknown column '1' in 'where clause' (SQL: update \`ratings\` set \`grade\` = 16级学生, \`star\` = 4, \`comment\` = very good where (\`class_id\` = \`1\` and \`id\` = \`6\`))
似乎正确的SQL命令应该使用quote''而不是``
有人可以帮我解决这个问题吗?
whereColumn方法可用于验证两列是否相等
因此,它试图将列class_id
与假设1作为列进行比较,并在1左右看回
而是使用where
功能
Ratings::where([['class_id', '=', $class_id], ['id', '=', $rating_id]])
->update(['grade' => $grade, 'star' => $star, 'comment' => $comment]);
请试试这段代码。
DB::table('table_name')->where('id','=',$request->input('id'))->update(['name'=>'jijo','address'=>'ernakulam']);