首页
读书
网课

正文

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 )



Db::name('a')->where('id',['=',3],['=',1],'or')->select();


推荐使用:$where[] = ['realname|username|nick_name','LIKE','%'.$v.'%','OR'];


sp242018年06月19日

条件的话直接写 $map['id'] = array(array('EQ',1),array('EQ',3),'OR');


sp242018年06月19日

Db::name('a')->where(array('id'=>array(array('EQ',1),array('EQ',3),'OR')))->select();


慕白2018年06月15日

回复 thinkphp : SELECT * FROM `a` WHERE ( `id` = 3 and `name` = '张三' ) OR (`sex`='男' and `age`=20);这种语句怎么写呢,看了好多资料还是没写出来。


回复scan_z2018年06月19日

用闭包,一个where 里面自动会 ()包含


scan_z2017年05月10日

正确回答:

Db::name('a')->where('id',['=',3],['=',1],'or')->select();




上一篇: 没有了
下一篇: 没有了
圣贤书院