Search code examples
yii

How show all queries to database in yii framework


In CodeIgniter I would do:

print_r ($this->db->queries);

In Yii I tried:

 print_r (Yii::app()->db)

But this doesn't show any queries.

UPDATE: I understand my problem: when I want to show db queries on a POST action, I don't show it. When using GET, it's ok.


Solution

  • As @bool.dev said, you can use CWebLogRoute or in my case i use CFileLogRoute to store these queries in file.

    array (
        'class'      => 'CFileLogRoute',
        'categories' => 'system.db.*',
        'logFile'    => 'sql.log',
    ),