我正在尝试使用post_system
或post_controller
挂钩来捕获和记录数据库表中的所有插入和更新查询。但是,发生的情况是该$queries = $CI->db->queries;
语句似乎根本没有捕获任何插入或更新语句。即使在各自的视图/控制器中插入新数据或更新旧数据时,它也只会捕获 SELECT 语句。
这是我的相关代码:
钩子.php
<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
// also tried with post_controller hook
$hook['post_system'] = array(
'class' => 'Db_query_log',
'function' => 'log_db_queries',
'filename' => 'db_log.php',
'filepath' => 'hooks'
);
钩子/db_log.php
<?php
class Db_query_log {
function __construct() {
//nothing special
}
function log_db_queries() {
$CI = & get_instance();
$queries = $CI->db->queries;
foreach ($queries as $key => $query) {
echo $query . "<br>";
// all statements displayed are SELECT statements even for UPDATE and INSERT operations performed by controllers where data is actually changed
}
}
}
这里的罪魁祸首可能是什么?我是否遗漏了什么,或者这个钩子只是忽略了 INSERT/UPDATE 操作?
任何帮助将不胜感激,谢谢!