如何在cakephp 1.2.6中回显最后一个查询

时间:2017-08-17 06:45:28

标签: php mysql debugging cakephp echo

我是cakephp的新手,在回复最后一个查询时遇到了麻烦。我想看看我正在执行的sql查询是什么因为它没有返回预期的结果。 cakephp的版本是1.2.6。 我试过以下代码

//$log = $this->Auction->getDataSource()->getLog(false, false); ( this does not work,  maybe due to old version )
$log =  $this->Auction->getDataSource()->showLog( false );

//debug($this->Auction->lastQuery()); ( same goes for this line. lastQuery is not working maybe due to old version) 

debug( $log ); 

此行显示

(default) 0 query took ms
Nr Query  Error   Affected    Num. rows   Took (ms)
public_html/controllers/auctions_controller.php (line 416)

(default) 0 query took ms
Nr    Query   Error   Affected    Num. rows   Took (ms)

但我想要的是要查看的SQL查询。

提前感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

在CakePHP 1.x中,您可以在DataSource::_queriesLog.

中访问所需的数据
$dbo = $this->getDatasource();
$logs = $dbo->_queriesLog;

return end($logs);