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'
);
-and this is hook defination-->
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);
}
}
--its creating query_log file --but no records of queries being stored
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/
There is an option "save_queries" which should be set to true
$db['default'] = array(
...
'save_queries' => TRUE
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With