thinkphp6 where优先级查询


$map[] = ['id','>',0];
$map[] = ['sex',1];
$map[] = ['color','blue'];

Db::name('student')
    ->where($map)
    ->where(['name','like','%efs%'])
    ->select();

SELECT * FROM `student` WHERE `id` > 0 AND `sex` = 1 AND `color` = 'blue' AND 'name' LIKE '%efs%';

Db::name('student')
    ->where([$map])
    ->where(['name','like','%efs%'])
    ->select();

SELECT * FROM `student` WHERE ( `id` > 0 AND `sex` = 1 AND `color` = 'blue' ) AND 'name' LIKE '%efs%';

一般情况下,where()连缀生成的sql语句是并列AND条件的,当出现优先时,如上所示,如要优先查询$map中的条件再查询'name'条件,只需在where()中加入'[]'即可

声明:Jefsky-程序猿甜品店|版权所有,违者必究|如未注明,均为原创|本网站采用BY-NC-SA协议进行授权

转载:转载请注明原文链接 - thinkphp6 where优先级查询


代码不一定每天都能写好,但人生每一天都要活好