企业🤖AI Agent构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
> `where`将会追加查询条件 > 下面是一些实用的例子: ```php //基础条件查询 Db('user')->select([ 'where' => [ 'age' => 12, 'username' => '张三' ] ])->get(); //sql:SELECT * FROM `user` WHERE `age` = 12 and `username` = '张三'; //查询年龄大于20的所有用户,传递一个数组,第一个值可以是任意的比较符号,还可以是in Db('user')->select([ 'where' => [ 'age' => array('>' , 20) ] ])->get(); //查询年龄大于20且小于40的用户,传递一个数组,第二个值为自定义的条件 Db('user')->select([ 'where' => [ 'age' => array('string' , '> 20 and age < 40') ] ])->get(); ``` > SQL小常识:在设置查询条件时,数据库会从左边进行处理条件,我们应该将过滤更多数据的条件置前,比如: > ```php > //条件2,过滤的数据比条件1多 > select * from news where lookNumber > 10 and type=1 > > //改写 > select * from news where type=1 and lookNumber > 10 > ```