I am working on a Project management system on PHP (CodeIgniter framework), Mysql, AJAX, XAMPP, JQUERY. I need a customizable table changes tracking tool which will log all changes into another table in same database for mysql. Basically I need to have a table which will have log details of updates, inserts and deletes on a database tables with what column has changed to what (summary). So that I can create a report from that table with changes to any particular table.
If there is no tool, I have already started working on my own solution where I am looking at two options.
One is having triggers on all tables which will create a row for each update and inserts with old data and new changed data. But here I need external user input as update comments from the user. How can I insert that data from a trigger. This is some what complex. Please suggest me any solution.
Second one is I will track the changes from PHP and insert every time when I do update and Insert which is more work but easier to implement.
Which one do you prefer? If not suggest me a tool which will take care of all this and insert into a new table in the same database. Or am I missing any thing simpler?
I definitely prefer doing this in application code rather than in the DB. An ORM is wonderful at handling this kind of thing as it gives an easy way of tracking and intercepting changes.
If you have a sensible abstraction over your database access then it should be pretty simple to intercept any database calls in your PHP code and do the logging there. Of course if you are building up SQL manually and then calling the database directly there is no central place for you to log changes.