在codeigniter中执行后记录所有查询

编程入门 行业动态 更新时间:2024-10-27 21:10:10
本文介绍了在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中执行后记录所有查询

本文发布于:2023-10-29 20:26:21,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1540654.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:codeigniter

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!