TP5.0版本mysql查询语句 闭包

Db::name('tiwen')
            ->where('user_id', $user_id)
            ->where(function ($query) {
                $query->where(function ($q1) {
                    $q1->where([
                        'is_status' => 3,
                        'is_pingjia' => 2
                    ]);

                })->whereOr(function ($q2) {
                    $q2->where([
                        'is_status' => 4,
                        'bohui_type' => 4
                    ]);
                });
            })
        ->count();

可以用buildSql打印输出语句是否与预期一致,如果不一致则需要根据需求进行调整

Db::name('tiwen')
            ->where('user_id', $user_id)
            ->where(function ($query) {
                $query->where(function ($q1) {
                    $q1->where([
                        'is_status' => 3,
                        'is_pingjia' => 2
                    ]);

                })->whereOr(function ($q2) {
                    $q2->where([
                        'is_status' => 4,
                        'bohui_type' => 4
                    ]);
                });
            })
        ->buildSql(true);

 

posted @ 2020-12-03 19:14  study_php_java_C++  阅读(281)  评论(0编辑  收藏  举报