[CakePHP]How to check SQL queries in Shell and Controller


[CakePHP1.3.3]

When you debug, within Controller and Model there is often something like SQL from the instant you’ve done $this->find().

At that time, either put the function below into vendor or if you read it in bootstrap you can confirm it in SQL any time.

Incidentally, within Shell things stripped of HTML are output so it’s very convenient.

When you set Configure::write(‘debug’, 2) or higher, it works.

function sql_dump($dbConfig = 'default', $exit = true) {
    ConnectionManager::getDataSource($dbConfig)->showLog();	
    if ($exit) { exit; } 
}


How to use it is as seen below.

class SampleShell extends Shell {
    public $uses = array('Sample');
    
    public function main() {
        $this->Sample->find('all');
        sql_dump();
    }
}
Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay
This entry was posted in CakePHP. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

3 Comments

  1. Posted %A %B %e%q, %Y at %I:%M %p | Permalink

    I agree with the post above and I will find more information from google.

  2. babar ali
    Posted %A %B %e%q, %Y at %I:%M %p | Permalink

    Very useful information. Specially debugging in shell script.

  3. Posted %A %B %e%q, %Y at %I:%M %p | Permalink

    Thanks for this. Helped me out in debugging a shell.

One Trackback

  1. [...] This post was mentioned on Twitter by Masaya Iwata, Masaya Iwata. Masaya Iwata said: Blog Updates, How to check SQL queries in Shell and Controller http://bit.ly/9AecmG [...]

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>