在没有 where 子句的 yii2 中计算 table 中的所有记录

Count all record in table in yii2 without where clause

我想计算 table 中的所有记录而不指定任何条件:

现在,我就是这样做的

$result['cms'] = Cms::find()->where([])->count();

它会给我结果,但我不想使用 where 子句。

那么如何计算没有where子句的所有记录。

谢谢

你可以看到这个文档http://www.yiiframework.com/doc-2.0/yii-db-activequery.html

只需使用

count(): returns COUNT 查询的结果。

Cms::find()->count();

all():returns 一个行数组,每一行都是名称-值对的关联数组。

Cms::find()->all();

有关更多信息,请参阅本指南http://www.yiiframework.com/doc-2.0/guide-db-query-builder.html