简体   繁体   中英

Yii2: Get raw sql of $query->count('*') in Yii2

I want to get the raw query for $query->count("*") .

I have tried

$s=$query->count("*");
$s=$s->createCommand()->sql;

It does not work.

Usually I do $s=$query->createCommand()->sql; to get raw sql which works fine. How to get it for count('*') . Please help.

You can't use createCommand() on $s , because count() method returns integer|string , it's not an object . To get count sql, you can use:

$query->select('count(*)')->createCommand()->sql

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