Show raw SQL query

20 1
5
Viewed: 266 697 times
Version: 2.0
Category: FAQs
Written by: darioo darioo
Updated by: darioo darioo
Created: Jan 14, 2017
Updated: 9 years ago

Here's a quick tip to dump the SQL for query.

$query = new Books::find()->where('author=2');
echo $query->createCommand()->sql;

or to get the SQL with all parameters included try:

$query->createCommand()->getRawSql()

Thanks to http://chris-backhouse.com/Yii2-Output-the-SQL-from-a-query-builder/1027