tp5 的查询构造器

dump(
  Db::table('destoon_ad')
  ->where('aid',1)
  ->find()
);

-----------------------------------------------------------

dump(
  Db::table('destoon_ad')
  ->field(['title','image_url'])
  ->where([
  'aid'=>['>',1],
  'pid'=>['>',24],
  ])
  ->select()
);

-----------------------------------------------------------

闭包函数

$pid = 24;
dump(
  Db::table('destoon_ad')
  ->field(['title','image_url'])
  ->where(function($query) use ($pid){
  $query->where('aid','>',1)
  ->where('pid','>',$pid);
  })
  ->select()

);

 

简写

$aid = 1;
dump(
  Db::select(function($query) use ($aid){
    $query->table('destoon_ad')
    ->field(['url'=>' 链接'])
    ->where([
    'aid'=>['>',$aid],
    'pid'=>['>',24]
    ]);
  })
);

 

posted @ 2018-04-15 11:43  我是谁,我在做什么  阅读(147)  评论(0编辑  收藏  举报