Print CakePHP Query

Leave a Comment
We may always want to know what query that's excuted when we use find('all'), find('list') or save() in CakePHP.
If I want know what is last excuted CakePHP query when we used CakePHP model find('all'). Use the following CakePHP script.
<?php
$logData = $this->User->getDataSource()->getLog();
pr( $logData );
?>
The above script will print all the queries that's excuted on the particular page. If I want to print last excuted CakePHP query use the following CakePHP script.

This CakePHP script will use the end() function to get last element of an array, and finally using echo statement it print last excted CakePHP query.

$logData = $this->User->getDataSource()->getLog();
$getLog = end($logData['log']);
echo $getLog['query'];
exit; 

0 comments:

Post a comment