|  | 
 
| 1、ID等于4 $result = Db::name('data')->where('id',4)->find();
 2、ID大于4
 $result = Db::name('data')->where('id','>=',4)->find();
 这里的'id','>=',4可以换成<=、<>、'in',[5,6,7,8]、'between',[5,8]
 3、查询某个字段是否为NULL$result = Db::name('data')->where('name','null')->select();
 
 4、使用exp条件表达式,表示后面在部分使用SQL原声语句查询,不建议用
 $result = Db::name('data')->where('id','exp'," like '%1%' ")->select();
 
 5、多个字段查询就多写几个where
 $result = Db::name('data')->where('id','>=',4)
 ->where('name','like','%5UCMS.COM%')
 ->select();
 或数组式where,但写起来麻烦,不推荐,知道可以这样写即可
 $result = Db::name('data')
 ->where([   'id' => ['>=',4],
 'name' => ['like','%5UCMS.COM%']->select();
 
 6、OR的话,where后多加其他条件,最后再加上'or'即可
 $result = Db::name('data')->where('id','>=',4)
 ->where('cid',['in',[1,2,3]],['>=',1],'or')
 ->limit(2)
 ->select();
 
 批量查询(不推荐,写起来麻烦)
 
 $result = Db::name('data')
 ->where([
 'cid' => [['in',[1,2,3]], ['>=',1], 'or')],
 'name' => ['like', '%php&']
 ])
 ->limit(2)
 ->select();
 
 
 7、快捷查询
 和用&符号,代表多个字段
 $result = Db::name('data')->where('id&status','>=',4)
 ->select();
 或用|符号,代表多个字段
 $result = Db::name('data')->where('id|status','>=',4)
 ->select();
 
 
 
 
 
 
 | 
 |