在使用TP框架写一个项目的时候,需要用到如
select * from table where (a = 1 or a = 2) and abc = 123;
请注意上面的 or 语句中是有括号包裹的。
正常我们的错误写法是:
Db:where(abc=123)->whereOr(a = 1 or a = 2)
生成的sql语句是不带 括号的
select * from table where a = 1 or a = 2 and abc = 123;
这时候是得不到我们想要的结果,where和whereor的输出乱了。
解决办法:
使用同一个where来进行处理
$whereor[] = array('origin|destination|phonenumber', 'like', "%" . $keywords . "%",'or');
$whereor[] = array('status', '=', $selstatus);
Supplys::where($whereor)->order('id', 'desc')->select();