Home > PHP Framework > ThinkPHP > What are the ThinkPHP queries for PHP?

What are the ThinkPHP queries for PHP?

WBOY
Release: 2023-05-30 13:06:08
forward
1086 people have browsed it

1. Aggregation query

In applications, we often use some statistical data, such as the number of current users (or those who meet certain conditions), the points of all users, The user's average score, etc., ThinkPHP provides a series of built-in methods for these statistical operations.

Get the number of users:

Db::table('think_user')->count();
// 助手函数
db('user')->count();
Copy after login

2. Time query

Use the where method.

The method supports time comparison, for example:

// 大于某个时间
where('create_time','> time','2016-1-1');
// 小于某个时间
where('create_time','<= time&#39;,&#39;2016-1-1&#39;);
// 时间区间查询
where(&#39;create_time&#39;,&#39;between time&#39;,[&#39;2015-1-1&#39;,&#39;2016-1-1&#39;]);
Copy after login

3. Quick query

The quick query method is a multi-field same query condition The simplified writing method of can further simplify the writing of query conditions. Use | to split between multiple fields to represent OR query, and use & to split to represent AND query. The following query can be implemented, for example:

Db::table(&#39;think_user&#39;)    ->where('name|title','like','thinkphp%')    ->where('create_time&update_time','>',0)    ->find();
Copy after login

The above is the detailed content of What are the ThinkPHP queries for 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