tp5中的一些where操作


快捷查詢

where('id&age','>',0); where('id|age','>',0); 

閉包查詢

$result = Db::name('data') ->select(function($query){$query->where('name','like','%think%') ->where('id','in','1,2,3')->limit(10); }); $result = Db::name('data') ->select(function($query){$query->where('name','like','%think%') ->where('id',' between',[1,3])->limit(10); });

獲取列數據,並且以id為索引

$list = Db::name('data') ->where('status',1) ->column('name','id');

聚合查詢

Db::name('data') ->where('id','>',1) ->count(); Db::name('data') ->where('id','>',1) ->max('age');

字符串查詢

$result = Db::table('user') ->where('id>:id and name is not null',['id'=>10]) ->select();

日期時間查詢

查詢大於某日的數據

$result = Db::table('user') ->whereTime('create_time','>','2017-01-01') ->select();

查詢本周的數據

$result = Db::table('user') ->whereTime('create_time','week') ->select();

查詢最近兩天添加的數據

$result = Db::table('user') ->whereTime('create_time','-2 days') ->select();

查詢一個時間范圍的數據

$result = Db::table('user') ->whereTime('create_time','between',['2017-1-1','2017-1-10']) ->select();

查詢上周的數據

$result = Db::table('user') ->whereTime('create_time','last week') ->select();


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM