1. Quick query
The quick query method is a simplified way of writing the same query conditions in multiple fields. It can further simplify the writing of query conditions. Use | between multiple fields. Split represents OR query, and split with & represents AND query. The following query can be implemented, for example:
Db::table('think_user') ->where('name|title','like','thinkphp%') ->where('create_time&update_time','>',0) ->find();
The generated query SQL is:
SELECT * FROM `think_user` WHERE ( `name` LIKE 'thinkphp%' OR `title` LIKE 'thinkphp%') AND ( `create_time` > 0 AND `update_time` > 0 ) LIMIT 1
Quick query supports all query expressions Mode.
2. Interval query
Interval query is a simplified way of writing multiple query conditions in the same field, for example:
Db::table('think_user') ->where('name',['like','thinkphp%'],['like','%thinkphp']) ->where('id',['>',0],['<>',10],'or') ->find();
The generated SQL statement For:
SELECT * FROM `think_user` WHERE ( `name` LIKE 'thinkphp%' AND `name` LIKE '%thinkphp') AND ( `id` > 0 OR `id` <> 10 ) LIMIT 1
The query conditions of interval query must be defined in array, and all query expressions are supported.
The above is the detailed content of Advanced query methods in ThinkPHP in PHP. For more information, please follow other related articles on the PHP Chinese website!