I would have to agree with Martin that DBIx::Log4perl will work quite well.
In the long term you might want to accomplish this by adding some
triggers on your DB tables to record this data as well.
This way all changes to the table will be caught at the DB end. So in
cases where someone is able to log in and make changes in some other
manner, other than your perl code, are caught as well.
It will also save a great deal of coding.
The caveat being this does make the DB a little slower and you need
space to store all these changes.
cheers
Martin Evans wrote:
aspiritus wrote:
Hello all experts !
I need to log every INSERT, UPDATE and DELETE queries even when using
placeholders. Here some code:
$sql = "UPDATE users SET `name`=? WHERE ìd`=1;";
$sth = $dbh->prepare($sql);
$sth->execute('Test User');
$sth->finish();
Of course execute params are given dynamically and I want to use
placeholders for more secure code.
I want to save that UPDATE query into file or database ( I'll prefer
DB :) ) for tracking purposes. Any idea how to do this?
DBIx::Log4perl will do this and more. Log4perl supports logging to
files and databases and a lot more and DBIx::Log4perl can be inserted
wherever you use DBI very easily. Whether the format will be how you
want it is another question but as I have an interest in
DBIx::Log4perl I would be happy to hear your suggestions.
Martin