Yii2 - Output the SQL from a query builder

Dump the Sql for a Query

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:


Did you know you can hire me?

I take on projects of all sizes. From Consulting to large Development Projects.

If you're starting a new Yii project and would like some help to get setup and running or you need some help with a particular module or you just need someone to develop the whole dang thing, then just ask ...

Leave a Comment

twitterfacebookgooglelinkedin https://me.yahoo.com