1. 程式人生 > >tp5閉包子查詢傳參方法

tp5閉包子查詢傳參方法

name mysq 方法 字段 包子 art class 傳參 HERE

在channel表中查詢status,channel_id,channel_name,account_level這些字段,且這些字段的channel_id不在adv_id為$id的表adv_channel_rule中:

$model = new Model();
$id = $req_models["id"];

tp5閉包子查詢傳參:

$res = $model->table(‘channel‘)
    ->field([‘status‘,‘channel_id‘,‘channel_name‘,‘account_level‘])
    ->where(‘channel_id‘,‘NOT IN‘,function
($query) use ($id) { $query->table(‘adv_channel_rule‘)->where("adv_id",$id)->field(‘channel_id‘); })->select();

mysql的原生寫法:

$res = ‘SELECT adv_id,adv_name,status,account_level FROM `channel` WHERE channel_id NOT IN (SELECT channel_id FROM adv_channel_rule WHERE adv_id=‘.$id.‘)‘;
$result = $model->query($res);

文章轉載:https://blog.csdn.net/weixin_36185028/article/details/79499872

tp5閉包子查詢傳參方法