Welcome Guest, Not a member yet? Register   Sign In
logging database queries
#1

[eluser]Unknown[/eluser]
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.
#2

[eluser]gunter[/eluser]
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
#3

[eluser]mezoni[/eluser]
Look at Profiler library code.

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

Look at DB_Driver code.

Code:
$this->queries[] = $sql;
#4

[eluser]Unknown[/eluser]
We just solved this problem by using an hook on "post_controller".
http://ellislab.com/codeigniter/user-gui...hooks.html

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

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




Theme © iAndrew 2016 - Forum software by © MyBB