Part of the EllisLab Network
   
 
logging database queries
Posted: 30 June 2007 06:23 AM   [ Ignore ]  
Summer Student
Total Posts:  3
Joined  01-05-2007

Been looking at db_debug and stuff like that, but I don’t find and obvious way to log all database queries to a file.
In fact I wan’t only to log any query that modifies the database.

Any suggestions on how to achieve this?

All my application code uses actice record so I was thinking of extending that class, so the methods that imply update, insert, delete would log the SQL query automtically. But since the active record class is not a library, I don’t believe I can extend it in the application/libraries folder the standard way.
How can I avoid modifying the CodeIgniter source and still achieve this?
An I don’t want to rely on manualy adding logging statements in the controller code itself.

Profile
 
 
Posted: 30 June 2007 01:21 PM   [ Ignore ]   [ # 1 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  206
Joined  04-27-2006

just a suggestion:
the profiler class shows all your queries if you want…
you could check, how it is done and copy and modify the profiler library to your purpose so it´s logging the query instead of displaying it…
and make it a post controller hook…
what a great idea…  smile

Profile
 
 
Posted: 01 July 2007 02:14 AM   [ Ignore ]   [ # 2 ]  
Summer Student
Total Posts:  9
Joined  03-18-2007

Look at Profiler library code.

if (class_exists('CI_DB_driver'))
{
  
foreach ($this->CI->db->queries as $val)
  
{
  }

Look at DB_Driver code.

$this->queries[] $sql
Profile
 
 
Posted: 04 February 2009 08:11 AM   [ Ignore ]   [ # 3 ]  
Summer Student
Total Posts:  1
Joined  02-04-2009

We just solved this problem by using an hook on “post_controller”.
http://codeigniter.com/user_guide/general/hooks.html

Its quit easy, you can handle all databasequerys from inside the hook by using:

this->CI =& get_instance();
foreach(
$this->CI->db->queries as $query)
{
   
... your code to log here
Profile