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);