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

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

    for cakephp 2.0 Write this function in AppModel.php

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

    To use this in Controller Write : echo $this->YourModelName->getLastQuery();

提交回复
热议问题