大佬教程收集整理的这篇文章主要介绍了如何在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); }
我怎么能在CakePHP 3.x中做到这一点?
找到数据源配置并设置’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,请注明来意。