脚本宝典收集整理的这篇文章主要介绍了如何在CakePHP 3.2中获取最后一次运行查询?,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
function getLastQuery() { Configure::wrITe('debug',2); $dbo = $this->getDatasource(); $LOGs = $dbo->getLog(); $lastLog = end($logs['log']); $latQuery = $lastLog['query']; echo "<PRe>"; print_r($latQuery); }
找到数据源配置并设置’log’=>真正
'Datasources' => [ 'default' => [ 'classname' => 'Cake\Database\Connection','driver' => 'Cake\Database\Driver\MysqL','PErsistent' => false,'host' => 'localhost',... 'log' => true,// Set this ] ]
如果您的应用程序处于调试模式,您将在页面显示sql错误时看到SQL查询.如果未启用调试模式,则可以通过添加以下内容将SQL查询记录到文件中:
配置/ app.PHP
找到日志配置并添加新的日志类型:
'Log' => [ 'debug' => [ 'className' => 'Cake\Log\Engine\FileLog','path' => LOGS,'file' => 'debug','levels' => ['notice','info','debug'],'url' => env('LOG_DEBUG_URL',null),],'error' => [ 'className' => 'Cake\Log\Engine\FileLog','file' => 'error','levels' => ['warning','error','critical','alert','emergency'],'url' => env('LOG_ERROR_URL',// Add the following... 'queries' => [ 'className' => 'File','file' => 'queries.log','scopes' => ['queriesLog'] ] ],
以上是脚本宝典为你收集整理的如何在CakePHP 3.2中获取最后一次运行查询?全部内容,希望文章能够帮你解决如何在CakePHP 3.2中获取最后一次运行查询?所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。