I want to get the last query CakePHP ran. I can't turn debug on in core.php and I can't run the code locally. I need a way to get the last sql query and log it to the error log without effecting the live site. This query is failing but is being run.
something like this would be great:
$this->log($this->ModelName->lastQuery);
Thanks in advance.
In CakePHP 1.x, the data you want is accessible in
DataSource::_queriesLog
. Cake doesn't really provide a getter method for this member, but the underlying language being PHP, nothing stops you from doing the following:In
app/app_model.php
:Combination of Matt's and blavia's solution (works when debug is not 2):
Simple you can use showLog() function