02/09/08
Zend framework: Logging Database Queries to FireBug
Logging database queries to FireBug is sinfully simple with the new component Zend_Db_Profiler_Firebug in ZF 1.6, now available, you can download it here Zend Framework Download Page.
Requirements:
- Firefox Browser ideally version 3 but version 2 is also supported.
- Firebug Firefox Extension.
- FirePHP Firefox Extension.
More information on requirements at the Zend Framework Documentation - Profiling with Firebug
Let’s look at some examples.
< ?php // Instatiate the database $db = Zend_Db::factory('Pdo_Mysql', array( 'host' => 'localhost', 'dbname' => 'zf_feature_testing', 'username' => 'user123', 'password' => 'pass123' ) ); // Instantiate the profiler in your bootstrap file $profiler = new Zend_Db_Profiler_Firebug('All Database Queries:'); // Enable it $profiler->setEnabled(true); // Attach the profiler to your db adapter $db->setProfiler($profiler); // Run your queries $result1 = $db->fetchAll('SELECT * FROM zf_test'); $result2 = $db->fetchAll('SELECT * FROM zf_test where id = ?', 3);
Alternatively you can add the profiler parameters to the Zend_Db factory.
< ?php // Instatiate the database, passing in the profiler parameters. $db = Zend_Db::factory('Pdo_Mysql', array( 'host' => 'localhost', 'dbname' => 'zf_feature_testing', 'username' => 'user123', 'password' => 'pass123', 'profiler' => array( 'enabled' => true, 'class' => 'Zend_Db_Profiler_Firebug' ) ) );
Or from an .ini file using Zend_Config_Ini
$config = new Zend_Config_Ini('../application/config.ini', 'development'); $db = Zend_Db::factory($config->database);
config.ini
[development] database.adapter = pdo_mysql database.params.host = localhost database.params.username = user123 database.params.password = pass123 database.params.dbname = zf_feature_testing database.params.profiler.enabled = true database.params.profiler.class = Zend_Db_Profiler_Firebug
Show me my profiling data?
Open FireBug, you will see a link under console.

Click it open and it will list all the queries that were run.

Enjoy!
Comments | RSS
[...] For a more detailed tutorial on how to use Zend_Db_Proflier_Firebug see here. [...]
Thanks for the great tutorial!
Hello Christoph!
Profiling db queries with FirePHP is like magic – thanks for showing this.
Is there a way to also display all db errors in a similar way? It would be very good to be able to see the db request that caused the error and not just a part of it like stack trace does.
Thanks.
SWK
Christoph would be the man ask that, http://www.christophdorn.com/Blog/2008/09/02/firephp-and-zend-framework-16/
[...] Zend framework: Logging Database Queries to FireBug [...]
[...] Enjoy! via peacocksuit.com [...]
hi,
Its an excellent news.
I have been working with zend framework based application.
So today, i thought let me search in google for “Zend framework firefox addons” with hope that i might get something interesting that would help me while developing the code.
So i found this nice components named “FirePHP”.
I will configure it in my local machine.
Thanks to the creator.
Grate job!!
Letsnurture
This dump profiler into Firebug is realy cool. I use it in the development phase. Thanks to that, I was able to find sites, that generate a lots of queries.
Leave a Reply