thinkphp5 数据库操作条件查询

发布时间:2019-12-31 09:07:29编辑:丝画阁阅读(182)

1,多条件模糊查询

$where[]=array('um.real_name|um.mobile','like',"%{$parameter['real_name']}%");


2,闭包查询

            $bwhere = array();
            $bwhere[] = array('type_id',"=",$type);
            $bwhere[] = array("their_id","=",$their_id);
            $bwhere[] = array("dispose_status","=",1);//等处理

$deployinfo = PartsAuditDeployLists::field("*")->where(function ($query) use($auth_id, $userid) {$query->where('role_id', $auth_id)->whereOr('user_id', '=', $userid);})->where($bwhere)->order("id asc")->find();

SELECT * FROM `dt_parts_audit_deploy_lists` WHERE ( `role_id` = 2 OR `user_id` = 165 ) AND `type_id` = 3 AND `their_id` = 10 AND `dispose_status` = 1 ORDER BY `id` ASC LIMIT 1




关键字