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
1602 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(&#39;think_user&#39;)    ->where(&#39;name&#39;,[&#39;like&#39;,&#39;thinkphp%&#39;],[&#39;like&#39;,&#39;%thinkphp&#39;])    ->where(&#39;id&#39;,[&#39;>&#39;,0],[&#39;<>&#39;,10],&#39;or&#39;)    ->find();
Copy after login

The generated SQL statement For:

SELECT * FROM `think_user` WHERE ( `name` LIKE &#39;thinkphp%&#39; AND `name` LIKE &#39;%thinkphp&#39;) 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:
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template