thinkphp 5中的混合查询
2021-02-18 22:17
阅读:491
标签:sel number keyword thinkphp php _id tor ati str 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‘)
thinkphp 5中的混合查询
标签:sel number keyword thinkphp php _id tor ati str
原文地址:https://www.cnblogs.com/luqiang213917/p/12938816.html
下一篇:css3
评论
亲,登录后才可以留言!