ThinkPHP
tp5中采用闭包的方式: $map['user_id']=1; $map['status']=0; $or_map['user_id']=$map['user_id']; $or_map['audit']=['in',['1,2']]; $list = Db::name('table')->where(function ($query) use ($map) { $query->where($map); })->whereOr(function ($query) use ($or_map) { $query->where($or_map); })->select(); //生成的sql语句: //SELECT * FROM `tp_table` WHERE ( `user_id` = '1' AND `status` = 0 ) OR ( `user_id` = '1' AND `audit` IN ('1,2') )
$where = [ 'feed_uid' => [ 'eq' , 5] , 'status' => [ [ 'eq' , 1] , [ 'eq' , 2 ] , [ 'eq' , 3 ] , 'or' ] , ]; $value = DealSpace::where($where)->count(); //最终的查询条件为where feed_uid=5 and (status=1 or status =2 or status =3 )
版权声明:本文为CSDN博主「瞳話cium」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。 原文链接:https://blog.csdn.net/weixin_42330073/java/article/details/86496940