1.手册样例thinkphp 5.0
Db::table('think_user')
->where('name',['like','thinkphp%'],['like','%thinkphp'])
->where(function($query){
$query->where('id',['<',10],['>',100],'or');
})
->select();
相当于sql语句:
SELECT * FROM `think_user` WHERE ( `name` LIKE 'thinkphp%' AND `name` LIKE '%thinkphp' ) AND ( `id` < 10 or `id` > 100 )
2.手册样例 thinkphp 5.1
Db::table('think_user')
->where('name', ['like', 'thinkphp%'], ['like', '%thinkphp'])
->where(function ($query) {
$query->where('id', ['<', 10], ['>', 100], 'or');
})
->select();
相当于sql语句:
SELECT * FROM `think_user` WHERE ( `name` LIKE 'thinkphp%' AND `name` LIKE '%thinkphp' ) AND ( `id` < 10 or `id` > 100 )
3.function($query)传参数用use()
样例:
Db::table('think_user')
->where($where)
->where(function($query) use($group_id){
$query->where(Db::raw("group_id is null or group_id = '$group_id'")); //Db::raw()可以直接写sql语句查询
})
->select();
Db::table('think_user')