我编写了以下代码来使用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命令应该使用引用''而不是“
有人可以帮我解决这个问题吗?
答案 0 :(得分:1)
whereColumn方法可用于验证两列是否相等
因此,它会尝试将列$ wget www.akshayud.me
--2017-12-19 08:03:18-- http://www.akshayud.me/
Resolving www.akshayud.me (www.akshayud.me)... 151.101.1.147, 151.101.65.147, 151.101.129.147, ...
Connecting to www.akshayud.me (www.akshayud.me)|151.101.1.147|:80... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: http://akshayud.me/ [following]
--2017-12-19 08:03:18-- http://akshayud.me/
Resolving akshayud.me (akshayud.me)... 162.255.119.148
Connecting to akshayud.me (akshayud.me)|162.255.119.148|:80... connected.
HTTP request sent, awaiting response... 302 Found
Location: http://www.akshayud.me/ [following]
--2017-12-19 08:03:18-- http://www.akshayud.me/
Connecting to www.akshayud.me (www.akshayud.me)|151.101.1.147|:80... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: http://akshayud.me/ [following]
--2017-12-19 08:03:18-- http://akshayud.me/
Connecting to akshayud.me (akshayud.me)|162.255.119.148|:80... connected.
HTTP request sent, awaiting response... 302 Found
Location: http://www.akshayud.me/ [following]
--2017-12-19 08:03:19-- http://www.akshayud.me/
Connecting to www.akshayud.me (www.akshayud.me)|151.101.1.147|:80... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: http://akshayud.me/ [following]
与假设1作为列进行比较,请参阅后面的1 -
而是使用class_id
功能
where
答案 1 :(得分:0)
请尝试此代码。
DB::table('table_name')->where('id','=',$request->input('id'))->update(['name'=>'jijo','address'=>'ernakulam']);