laravel/lumen查询构建器中的问题whereColumn方法 [英] Issue in laravel/lumen query builder whereColumn method
本文介绍了laravel/lumen查询构建器中的问题whereColumn方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
- 流明版本:5.5
- PHP版本:7.0
我编写了以下代码,以使用whereColumn方法更新数据:
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]);
会产生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命令应使用引号''而不是``
it seems that the correct SQL command should use quote '' instead of ``
有人可以帮我解决这个问题吗?
Can someone help me solve this problem?
推荐答案
whereColumn方法可用于验证两列是否相等
The whereColumn method may be used to verify that two columns are equal
因此,它尝试比较列 class_id
并假设1为列,请参阅1前后的引号
Therefore it tries to compare column class_id
with assuming 1 as a column see back-ticks around 1
代替使用 where
函数
Ratings::where([['class_id', '=', $class_id], ['id', '=', $rating_id]])
->update(['grade' => $grade, 'star' => $star, 'comment' => $comment]);
这篇关于laravel/lumen查询构建器中的问题whereColumn方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文