快捷查询方式是一种多字段相同查询条件的简化写法,可以进一步简化查询条件的写法,在多个字段之间用 | 分割表示or查询,用 & 分割表示and查询,可以实现下面的查询,例如:
db::table('think_user') ->where('name|title','like','thinkphp%') ->where('create_time&update_time','>',0) ->find();
生成的查询sql是:
select * from `think_user` where ( `name` like 'thinkphp%' or `title` like 'thinkphp%') and ( `create_time` > 0 and `update_time` > 0 ) limit 1
快捷查询支持所有的查询表达式。
2.区间查询
区间查询是一种同一字段多个查询条件的简化写法,例如:
db::table('think_user') ->where('name',['like','thinkphp%'],['like','%thinkphp']) ->where('id',['>',0],['<>',10],'or') ->find();
生成的sql语句为:
select * from `think_user` where ( `name` like 'thinkphp%' and `name` like '%thinkphp') and ( `id` > 0 or `id` <> 10 ) limit 1
区间查询的查询条件必须使用数组定义方式,支持所有的查询表达式。
以上就是php中thinkphp的高级查询方法的详细内容。
