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

后端 未结 8 1277
余生分开走
余生分开走 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:36

    There are four ways to show queries:

    1. This will show the last query executed of user model:

      debug($this->User->lastQuery());  
      
    2. This will show all executed query of user model:

      $log = $this->User->getDataSource()->getLog(false, false);       
      debug($log);
      
    3. This will show a log of all queries:

      $db =& ConnectionManager::getDataSource('default');
      $db->showLog();
      
    4. If you want to show all queries log all over the application you can use in view/element/filename.ctp.

      element('sql_dump'); ?>
      

提交回复
热议问题