问题
- Lumen Version: 5.5
- PHP Version: 7.0
I wrote following code to update data by using whereColumn method:
Ratings::whereColumn([['class_id', '=', $class_id], ['id', '=', $rating_id]])->update(['grade' => $grade, 'star' => $star, 'comment' => $comment]);
which generate a SQL error:
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\`))
it seems that the correct SQL command should use quote '' instead of ``
Can someone help me solve this problem?
回答1:
As per docs
The whereColumn method may be used to verify that two columns are equal
Therefore it tries to compare column class_id
with assuming 1 as a column see back-ticks around 1
Instead use where
function
Ratings::where([['class_id', '=', $class_id], ['id', '=', $rating_id]])
->update(['grade' => $grade, 'star' => $star, 'comment' => $comment]);
回答2:
Please try this code.
DB::table('table_name')->where('id','=',$request->input('id'))->update(['name'=>'jijo','address'=>'ernakulam']);
来源:https://stackoverflow.com/questions/47880881/issue-in-laravel-lumen-query-builder-wherecolumn-method