简体   繁体   中英

Count all record in table in yii2 without where clause

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM