Count all record in table in yii2 without where clause

老子叫甜甜 提交于 2019-12-20 01:39:03

问题


I want to count all record from table without specify any condition :

now, i am doing by this way

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

and it will give me result,but i don't want to use where clause.

So how to count all records without where clause.

Thank you


回答1:


You can see this doc http://www.yiiframework.com/doc-2.0/yii-db-activequery.html

simply using

count(): returns the result of a COUNT query.

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

all(): returns an array of rows with each row being an associative array of name-value pairs.

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

see this guide for more http://www.yiiframework.com/doc-2.0/guide-db-query-builder.html



来源:https://stackoverflow.com/questions/37338557/count-all-record-in-table-in-yii2-without-where-clause

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!