tags:

views:

43

answers:

2

Is there a way that one can cause CakePHP to dump its SQL log on demand? I'd like to execute code up until a point in my controller and see what SQL has been run.

+1  A: 

If you're using CakePHP 1.3, you can put this in your views to output the SQL:

<?php echo $this->element('sql_dump'); ?>

So you could create a view called 'sql', containing only the line above, and then call this in your controller whenever you want to see it:

$this->render('sql');

(Also remember to set your debug level to at least 2 in app/config/core.php)

Source: http://book.cakephp.org/view/1567/Model-Databases-and-Datasources

handsofaten
+1  A: 

Try this:

$log = $this->Model->getDataSource()->getLog(false, false);
debug($log);

http://api13.cakephp.org/class/dbo-source#method-DboSourcegetLog

You will have to do this for each datasource if you have more than one though.

deceze