laravel查看执行的SQL语句,以及orWhere复杂情况判断

/*
 * 会员测试--模型中的方法
 */
public function test($conditionEQ,$conditionWH){
    //var_dump($conditionWH);exit;
    DB::connection()->enableQueryLog();
    $res = DB::table('member')
            ->where($conditionEQ)
            ->where(function ($query) use ($conditionWH){
                    $query->orWhere($conditionWH);
            })->get();
    var_dump(DB::getQueryLog());
    return $res;
}
/**
*测试环境中的方法
*/
class TestController extends Controller
{
    public function test(){
        $model_member = new MemberModel();
        $conditionEQ[] = array('member_state','=',1);
        $conditionEQ[] = ['is_buy','=',1];
        $conditionEQ[] = ['member_id','<',100];
        $conditionWH[] = ['member_name','like',"%LAL%"];
        $conditionWH[] = ['member_mobile','like','188%'];
        $res = $model_member->test($conditionEQ,$conditionWH);
        var_dump($res);
    }
}
白发渔樵

白发渔樵

发表评论

电子邮件地址不会被公开。 必填项已用*标注