我有区域表:
-----------------------------
id | name | level
-----------------------------
1 | India | country
2 | Some?thing | country
在此表中,我添加了一行问号,我想选择该行如下 用口才查询:
Area::select(*)->where("name","LIKE", "%Some?thing%")
->where("level","=","country")->get();
但是这不会给出结果,因为在条件替换为绑定的字符串中的问号
生成的原始sql是:
select * from area where name like %Somecountrything% AND level = ?
但我希望它像
select * from area where name like %Some?thing% AND level = country
答案 0 :(得分:3)
试试这个:
Area::whereRaw("name LIKE '%Some?thing%'")
->where("level","=","country")->get();
您可以在whereRaw()
答案 1 :(得分:1)
将<{1}}用于此
像
whereRaw()
输出如下:
DB::table('users')->whereRaw("email LIKE '%Some?thing%'")->get();
Print_r(DB::getQueryLog());
希望这有帮助!
答案 2 :(得分:1)