Jump to content

Logging of all database changes


aniesh82

Recommended Posts

Hi,

 

I would like to hear from you all about the Logging of all database changes.

 

I have lots of tables in the database and many user have the permissions to edit these details. But the Super Admin, can view all the changes, like the old data, new data, who changed, changed date & time.

 

I need these data to be logged whenever someone makes changes and able to see in future also.

 

Any package is available for doing this task ? Also, if you have any great idea about this, please share that also.

 

Thank You.

 

Link to comment
https://forums.phpfreaks.com/topic/130844-logging-of-all-database-changes/
Share on other sites

If you're just looking for a basic way to log the changes and nothing more, then you could probably write a script yourself that logs all the changes in a text file.

 

For example, create a file called 'logs.txt', and place it in an appropriate directory.

 

<?php

$sql = 'UPDATE table_name .............';

if ( mysql_query( $sql ) )
{
    // The table has been changed, so you can update the logs file
    // First get all the current logs

    $contents = file_get_contents( 'logs.txt' );

    // Create the new log

    $new_log = 'SQL: '.$sql.' Date: '.date( 'D-m-y etc ..').'';

    // Open the logs file and write the new log/old logs to it

    $open = fopen( 'logs.txt', 'w' );

    fwrite( $open, $new_log.$contents );

    fclose( $open );
   
}

?>

 

It's not brilliant and I don't know if it works, but you get my point :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.