[Snippet] Get last SQL query in CakePHP Controller

Sometimes, whilst debugging, it is useful to see the last SQL query that CakePHP executed. This is easy if you are in the view, however not so easy in the Model or Controller.
Here’s how I over came the issue.

$log = $this-&gt;TheModelName-&gt;getDataSource()-&gt;getLog(false, false); debug($log);
<span style="line-height: 1.5em;">

Author: Kieran Barnes

Kieran is a PHP developer with 15 years commercial experience. Specialist in WordPress, CakePHP, CubeCart and all things PHP.

1 thought on “[Snippet] Get last SQL query in CakePHP Controller”

Leave a Reply

Your email address will not be published. Required fields are marked *