I have created a hook for query log. Step 1 : $config['enable_hooks'] = TRUE;
in config.php
Step 2 :
$hook['post_controller'] = array(
'class' => 'Db_log',
'function' => 'logQueries',
'filename' => 'db_log.php',
'filepath' => 'hooks'
);
// hooks.php
Step 3 : Hooks folder created the file called Db_log.php
Step 4 : Code in // Name of Class as mentioned in $hook['post_controller]
class Db_log {
function __construct() {
// Anything except exit()
}
// Name of function same as mentioned in Hooks Config
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) {
date_default_timezone_set("Asia/Bangkok");
$sql = $query . "
Execution Time:" . $times[$key];
fwrite($handle, $sql . "
");
}
$line .= "-----------------------------------------------
";
fwrite($handle, $line . "
");
fclose($handle); // Close the file
}
}
My Question is When ever controller is call then hook is running properly in local On server hook is not working, Set the permission 755,777,644 but still not working.
Please change array in hooks.php as bellow
$hook['post_controller'] = array(
'class' => 'Db_log',
'function' => 'logQueries',
'filename' => 'Db_log.php',
'filepath' => 'hooks'
);
You have written wrong file name