How can I see CakePHP's SQL dump in the controller?

Justin picture Justin · Sep 5, 2010 · Viewed 141.1k times · Source

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.

Answer

deceze picture deceze · Sep 6, 2010

Try this:

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

http://api.cakephp.org/2.3/class-Model.html#_getDataSource

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