How to ECHO or PRINT SQL query


I tried to find a simple way to echo the actual SQL query that I'm trying to execute. (for testing/checking purposes)

something like:


but no luck :(



maybe you set enableProfiling = true in your config (db)

then add a CProfileLogRoute as a route for the CLogRouter

this dumps all your queries at the bottom of your page

Add trace level in your log configuration inside protected/config/main.php

Or in case you want a mysql query trace (and ofc you use mysql), add:

log = /tmp/mysql.log 

to your my.cnf file and restart mysql daemon.

I think both will do.


so this is not exactly what I was looking for, but it will do for now. (it's kinda weird that Yii doesn't have a simple solution for this)

so my main.php looks like this:







                    'levels'=>'error, warning',




                    'levels' => 'trace',




and a little bit below …








and this will display everything on the bottom part of the screen

thanks everybody for the help,


wow works perfectly!  :o

Nice feature I didn't know.

My log is giving me SQL queries before the parameters have been replaced.  Eg.

Executing SQL: INSERT INTO `Slug` (`ownerId`, `ownerTable`, `slug`) VALUES

(:yp0, :yp1, :yp2)


Querying SQL: SELECT COUNT(*) FROM `Slug` WHERE LOWER(slug)=?

Is there any way to see them with the parameters actually within the query?  It makes it kind of hard to see what's going on.

You may configure your db connection with enableParamLogging=true.

You should turn off this in production, however, because it degrades your overall performance.