Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Jun 2007
    Location
    Canada
    Posts
    49
    Thanks
    1
    Thanked 1 Time in 1 Post

    Maintaining an audit log

    I would like to maintain an audit (change) log for changes to my database. Along the idea of user xxx changed price1 from $yyy to $zzz on ddd/mm/yy

    There are about 20-30 fields involved. The only two ways that I can think of to have an audit log are to a) have a hidden copy on the forms of the original value and compare hidden to user entered or b) make a temp copy of the DB record before update and compare it to the new record.

    Is there a more practical way of maintaining an audit log? This seems like a huge amount of over-head for this task.

    Thanks
    Of all the things I've lost in my life time, my mind is the one I miss the most!

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    There's a rather simple way, but (assuming you're using MySQL) you'll need version 5.02+ and your tables will need to be type Innodb. If those two things are true, you can use triggers. A trigger is an action that happens every time some action occurs on the table. For example, you can set a trigger so if a row is updated in a table, then a row is inserted into an audit table showing what got updated.

    More info:

    http://dev.mysql.com/doc/refman/5.0/en/triggers.html

  • #3
    New Coder
    Join Date
    Jun 2007
    Location
    Canada
    Posts
    49
    Thanks
    1
    Thanked 1 Time in 1 Post
    Are there any other techniques for accomplishing this? The server I am using is still on PHP 4.
    Of all the things I've lost in my life time, my mind is the one I miss the most!

  • #4
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,642
    Thanks
    2
    Thanked 405 Times in 397 Posts
    You mean MySQL4? The version of PHP doesn't matter.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •