Issue in laravel/lumen query builder whereColumn method

爷,独闯天下 提交于 2021-01-28 08:30:41

问题


  • 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!