Question

I have several tables like as attendance, fee, salary, leave etc.

In this system has more than one admin,subadmin etc.

I need to keep a track who add new information and who edit the current data, also I have to keep previous data.

How could I design my database for tracking this database. My plan is given below:

       For adding track:
             AddBy(id(row id of adding information),table_name,adder).

       For editing track:
            editBy(id(row id of adding information),table_name,field_Name,previousData,editor)

Is it sufficient for tracking one and which data is changed ?

Was it helpful?

Solution 3

Think Different's answer is better. But you can change this as:

 id | table_name | operation |previous_data(with fields)| user_id | ch_time
 -----------------------------------------------------------
 1    fee_table    INSERT    id:120,fee:250    1      2014-04-13 09:10:53
 2    fee_table    UPDATE    id:10,fee:50      2      2014-04-16 09:10:53
 3    fee_table    DELETE    id:120,fee:250    1      2014-04-18 09:10:53

For storing data use your mvc serialized data. Use php serialize() and unserialize() function. As: $sqldata = array (serialize($session_data), $_SERVER['PHP_AUTH_USER']);

OTHER TIPS

I would create a table named operation_logs like:

id | table_name | table_pk | operation | used_id | log_time
-----------------------------------------------------------
 1   fee_table      5         INSERT       1        2014-04-15 09:10:53
 2   fee_table      9         UPDATE       2        2014-04-16 09:10:53
 3   fee_table      5         DELETE       1        2014-04-17 09:10:53

Something like that

As far as I understand the scenario you´re basically looking for a trigger. https://dev.mysql.com/doc/refman/5.1/en/create-trigger.html

A trigger is a routine that is invoked whenever an operation (one of those given in the trigger definition) is performed on a table row. The trigger function would be a stored procedure that - in your case - stores the old content of the row (in case of an update) to a log table.

If it comes to data being inserted I´d just add columns like "created_by" (default to the current user name) and created_time (default to current_timestamp).

I hope this helps!

You can add a column in your desired table named 'userID'. In general practice whenever a user is logged on then that particular user's data can be retrieved and stored in an object. or user's Id can be stored in a session variable directly or from that object.

After that, save that user's id from the session during each 'Add' or 'Edit' Operation. In this way you will be able to keep track whoever did which operation.

Additional columns of the table may be: operation type, operation time. Or you can use a global table with another additional column named 'table name', if you do not want individual table for each task.

Thanks

I find out a technique for this,Any body can modify or suggest me. I will keep my data into a table using php serialize function. Create a table named history like as

 history(id,target_table(name of the table), target_id (ID of the saved entry),create/edit/change data (serialized data of the saved row),date)

All of data that is changed or edit or delete, all of these are kept into this table using serialize and when need these data, I will make them unserialize.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top