Profiling your database in Zend Framework

Just a quick tip for all Zend Framework developers.

Imagine I’m getting an error from a select that I’ve created:

$questionRow = $this->fetchRow($select);

If you want to see which query is being executed on your database, you can go with something like that:

$db = Zend_Db_Table::getDefaultAdapter();
$profiler = $db->getProfiler()->setEnabled(true);
// like before
$questionRow = $this->fetchRow($select);
$query = $profiler->getLastQueryProfile();

That will print the SQL query that has just been executed.