在没有where子句的情况下计算yii2中表中的所有记录 [英] Count all record in table in yii2 without where clause
本文介绍了在没有where子句的情况下计算yii2中表中的所有记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在不指定任何条件的情况下计算表中的所有记录:
I want to count all record from table without specify any condition :
现在,我这样做
$result['cms'] = Cms::find()->where([])->count();
它会给我结果,但我不想使用 where 子句.
and it will give me result,but i don't want to use where clause.
那么如何在没有where 子句的情况下统计所有记录.
谢谢
推荐答案
你可以看到这个文档 http://www.yiiframework.com/doc-2.0/yii-db-activequery.html
简单地使用
count():返回 COUNT 查询的结果.
count(): returns the result of a COUNT query.
Cms::find()->count();
all():返回一个行数组,每一行都是一个名称-值对的关联数组.
all(): returns an array of rows with each row being an associative array of name-value pairs.
Cms::find()->all();
查看本指南了解更多 http://www.yiiframework.com/doc-2.0/guide-db-query-builder.html
这篇关于在没有where子句的情况下计算yii2中表中的所有记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文