Welcome Guest, Not a member yet? Register   Sign In
Log queries for auditing purposes
#1

[eluser]Unknown[/eluser]
I am building an application where there is the need to keep track of all changes made to the data stored in the db, for auditing purposes. Is there any way to retrieve a query built by Active Records, so that it can be logged somewhere? I can't just rely on the MySQL server log files, as I also need to log other information that wouldn't be available there.
#2

[eluser]designfellow[/eluser]
Hi,

You can use
$this->db->last_query();
to findout the last run query.

Happy Coding,
DesignFellow
#3

[eluser]omar-303[/eluser]
I think if you enabled the Profiler you will see all queries been made.

User Guide :
http://ellislab.com/codeigniter/user-gui...iling.html
#4

[eluser]Unknown[/eluser]
Thanks, both of you. In the end, thanks to the fact that I am using PHP5, the solution was much easier than I thought.

I noticed that $this->db->queries would show me all the queries executed by a controller. Since I had already created a MY_Controller class, which all other controllers were extending, I simply added a __destruct() method where I look for all insert/update/delete queries and log them to the db, along with other information I need.

There might be better and more elegant ways to accomplish the task, but this will do just fine for me.




Theme © iAndrew 2016 - Forum software by © MyBB