5

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.

2

3 Answers 3

5

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',
),
Sign up to request clarification or add additional context in comments.

1 Comment

For me CWebLogRoute better. Thank you.
0

To complement @snippLeaf-com's answer, you can trace this file filtering by the keywords you want like this:

// filter by "INSERT" or "UPDATE"
$ tail -f /path_to/protected/runtime/sql.log |grep 'INSERT\|UPDATE'

// filter (case insensitive) by "SELECT" in table "x2_users"
$ tail -f /path_to/protected/runtime/sql.log |grep -i SELECT.*x2_users

OBS: to get fresh data you could need refresh database cache:

rm -f protected/runtime/cache/*.bin

Comments

0

If you really want every query log in yii use yii db profiler extension.

Step1. Download extension from --> link

Step2. Unpack to protected/extensions/

Step3. Rename folder name yii-db-profiler-master to db_profiler

Step4. Update the following to your protected/config/main.php:

<?php
return array(
    // …
    'components' => array(
        // …
        'db' => array(
            // …
            'enableProfiling'=>true,
            'enableParamLogging' => true,
        ),
        'log'=>array(
            'class'=>'CLogRouter',
            'routes'=>array(
                    // …
                    array(
                        'class'=>'ext.db_profiler.DbProfileLogRoute',
                        'countLimit' => 1, // How many times the same query should be executed to be considered inefficient
                        'slowQueryMin' => 0.01, // Minimum time for the query to be slow
                    ),
            ),
        ),
    ),
);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.