Home > PHP Framework > ThinkPHP > Advanced query methods in ThinkPHP in PHP

Advanced query methods in ThinkPHP in PHP

PHPz
Release: 2023-05-30 18:31:06
forward
1548 people have browsed it

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();
Copy after login

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
Copy after login

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();
Copy after login

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
Copy after login

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!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template