To log the queries in cake php2 without setting the debug =2

65 Views Asked by At

I am using function getLastQuery() with debug value=2 in config file then it will provide us the last executed query but I have to work on a live website where we can not able to set debug=2 because if When we do this all warnings and errors start appearing in the frontend. So I want to use getLastQuery() function with debug=0 but it doesn't work.

Please suggest some alternative to this to print the last executed query without setting debug=2.

I tried this

$query = $this->ShopifyProduct->getLastQuery();
1

There are 1 best solutions below

0
Bhargav Chudasama On

In CakePHP 2, to log the queries without setting the debug level to 2, you can add the following code to your controller or model:

$this->YourModel->getDataSource()->getLog(false, false);

You can then use CakePHP's CakeLog class to write the query log to a file or any other destination. For example:

App::uses('CakeLog', 'Log');
CakeLog::write('debug', print_r($this->YourModel->getDataSource()->getLog(false, false), true));