SQL Logging and Profiling in FireBug (Yii 1.1)

During development, it's often very handy to have SQL logging and profiling.

I found that this was tricky in Yii 1.0, but with Yii 1.1, I'm pleased to say, this is now much easier. While the new CWebLogRoute, by default, will inject it's output after the </html> tag, producing invalid markup and often resulting in strange rendering artifacts, logging to the FireBug console is a very useful feature!

Personally, I prefer to build this into my "index.php" file - here's an example of how to modify the configuration depending on the domain name, to have the SQL logging and profiling turned on when you're testing your site from a local domain.

Example "index.php" file:

// change the following paths if necessary

// remove the following line when in production mode
if ($_SERVER['HTTP_HOST'] == 'localhost') { 
    defined('YII_DEBUG') or define('YII_DEBUG',true);
    $config['components']['log']['routes'][] = array(
    $config['components']['db']['enableProfiling'] = true;
    $config['components']['db']['enableParamLogging'] = true;


It's as simple as that - now run the site with FireBug enabled, and you should see your SQL queries, with parameters, displayed on the Console tab in FireBug!

Links ΒΆ

Russian version

6 0
Viewed: 32 548 times
Version: 1.1
Category: Tutorials
Tags: Logging
Written by: mindplay
Last updated by: qiang
Created on: Dec 24, 2009
Last updated: 9 years ago
Update Article


View all history

Related Articles