简体   繁体   中英

way to manage audit trail of changing record in mysql

I am building a application. It is basically a E-commerce Order fulfillment application. IN this audit trials ie who changed what and how many times it was changed and others make a important aspect. How should i maintain this in database / table level ? Say if a record is altered by 3 people, how will i maintain all the changes and track of who changed what ?

First, you need create for every table which you want track with structure like this:

create table user_track_logs {

    id bigint(20) primary key auto_increment,
    key_id int (11),
    user_id (int),
    created timestamp default now(),
    field varchar(128)// set bigger if you have long named columns (like this_columns_is_very_important_for_me_and_my_employers...)
    field_value_was text null,
    field_value_new text null,    
}

Second you need set current user ID in var in MySQL's connection, or you can use MySQL's user. You can create for every user separate MySQL's login.

Third create triggers insert/update/delete which will be store in user_track_logs .

Or you can emulate this process in PHP, but in PHP it will be more difficult.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM