在codeigniter中执行后记录所有查询 [英] logging all queries after execution in codeigniter
本文介绍了在codeigniter中执行后记录所有查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在使用钩子执行后记录所有查询。
-i在config.php中启用了钩子
-这是我的钩子->
i want to log all queries after execution using hooks. -i enabled hooks in config.php -this is my hook-->
$hook['post_controller'] = array(
'class' => 'Db_log',
'function' => 'logQueries',
'filename' => 'db_log.php',
'filepath' => 'hooks'
);
-这是勾子定义->
class Db_log
{
function __construct()
{
}
function logQueries()
{
$CI = & get_instance();
$filepath = APPPATH . 'logs/Query-log-' . date('Y-m-d') . '.php';
$handle = fopen($filepath, "a+");
$times = $CI->db->query_times;
foreach ($CI->db->queries as $key => $query)
{
$sql = $query . " \n Execution Time:" . $times[$key];
fwrite($handle, $sql . "\n\n");
}
fclose($handle);
}
}
-创建query_log文件
-但没有存储查询记录
--its creating query_log file --but no records of queries being stored
推荐答案
您的代码看起来不错-唯一的原因工作在您的数据库配置中-在application / config /
Your Code looks fine - the only reason why this doesn't work is in your DB Configuration - take a look @your DB Connection in the database.php under application/config/
应设置选项 save_queries变为真
There is an option "save_queries" which should be set to true
$db['default'] = array(
...
'save_queries' => TRUE
);
这篇关于在codeigniter中执行后记录所有查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文