Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to get last query executed in Cakephp ?

    • 0
    • 0
    • 0
    • 0
    • 1
    • 0
    • 0
    • 0
    • 3.24k
    Comment on it

    Get last query run in Cakephp 2.x :

    There is a situation when we need to check what was the last query which was executed in Cakephp. My purpose for writing this blog is to provide you the solution for this as I was also stuck here.

    I wanted to get the last query CakePHP ran. I was not able to turn the debug mode on in core.php and was not able to run the code locally as well. So the best way which will get the last sql query is use the getDatasource and getLog method.

     

    For Cake 2.x, you can test the following lines of code:

     

    function getLastQuery() {
      $dbo = $this->getDatasource();
      $logs = $dbo->getLog();
      $lastLog = end($logs['log']);
      return $lastLog['query'];
    }

     

    Thanks for reading the blog.

 1 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: