TP5.1 whereOr查询
tp5 给的whereOr方法在不仔细阅读文档的情况下会遇到一些问题
先看下代码:
$this->modelLineModel->where('status',1)->whereOr(['area1_id'=>2341,'area2_id'=>2])->select();
想着应该是whereOr里面的并且的关系,然后或者上stauts=1 , 然而并非如此,它的sql为:
SELECT * FROM `sdb_line` WHERE `area1_id` = 2341 OR `area2_id` = 2 AND `status` = 1
怎么才能达到上面想要的结果呢?仔细看下文档就明白了:
$map1 = [ ['name', 'like', 'thinkphp%'], ['title', 'like', '%thinkphp'], ]; $map2 = [ ['name', 'like', 'kancloud%'], ['title', 'like', '%kancloud'], ]; Db::table('think_user') ->whereOr([ $map1, $map2 ]) ->select();
生成的sql为:
SELECT * FROM `think_user` WHERE ( `name` LIKE 'thinkphp%' AND `title` LIKE '%thinkphp' ) OR ( `name` LIKE 'kancloud%' AND `title` LIKE '%kancloud' )
看到文档的列子就基本知道用法了
by:wangyang