I am trying to use post_system
or post_controller
hook to catch and log all insert and update queries in a database table. But, what happens is that the $queries = $CI->db->queries;
statement doesn't seem to catch any insert or update statement at all. It only catches SELECT statements even when new data is inserted or old data is updated in respective views/controllers.
Here is my relevant code:
hooks.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'
);
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
}
}
}
What could be the culprit here? Am I missing something or this hook simply ignores INSERT/UPDATE operations?
Any help would be appreciated, thanks!