You are viewing revision #1 of this wiki article.
This is the latest version of this article.
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
Great, thx for this code my friend!
i have tried all this work:
To get SQL with no bound params:
$query->createCommand()->sql;
Equivalent to below:
$query->createCommand()->getSql();
To get SQL with bound params:
$query->createCommand()->rawSql;
Equivalent to below:
$query->createCommand()->getRawSql();
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.