PHP的ThinkPHP查询有哪些

来源:undefined 2024-12-29 03:30:05 1043

1、聚合查询

在应用中我们经常会用到一些统计数据,例如当前所有(或者满足某些条件)的用户数、所有用户的积分、用户的平均成绩等等,ThinkPHP为这些统计操作提供了一系列的内置方法

获取用户数:

1

2

3

Db::table(think_user)->count();

// 助手函数

db(user)->count();

登录后复制

2、时间查询

使用 where方法。

1

2

3

4

// 大于某个时间

where(create_time,> time,2016-1-1);

// 小于某个时间

where(create_time,<p><strong>3、快捷查询</strong></p><p>快捷查询方式是一种<strong>多字段相同查询条件</strong>的简化写法,可以进一步简化查询条件的写法,在多个字段之间用 | 分割表示OR查询,用 &amp; 分割表示AND查询,可以实现下面的查询,例如:</p><pre class="brush:php;toolbar:false">Db::table(think_user)    -&gt;where(name|title,like,thinkphp%)    -&gt;where(create_time&amp;update_time,&gt;,0)    -&gt;find();

登录后复制

以上就是PHP的ThinkPHP查询有哪些的详细内容,更多请关注php中文网其它相关文章!

最新文章