How can I see CakePHP's SQL dump in the controller?

后端 未结 8 1151
余生分开走
余生分开走 2020-12-04 06:04

Is there a way that one can cause CakePHP to dump its SQL log on demand? I\'d like to execute code up until a point in my controller and see what SQL has been run.

相关标签:
8条回答
  • 2020-12-04 06:43

    In CakePHP 1.2 ..

    $db =& ConnectionManager::getDataSource('default');
    $db->showLog();
    
    0 讨论(0)
  • 2020-12-04 06:46

    If you're using CakePHP 1.3, you can put this in your views to output the SQL:

    <?php echo $this->element('sql_dump'); ?>
    

    So you could create a view called 'sql', containing only the line above, and then call this in your controller whenever you want to see it:

    $this->render('sql');
    

    (Also remember to set your debug level to at least 2 in app/config/core.php)

    Source

    0 讨论(0)
提交回复
热议问题