Ronald Wiplinger wrote:
I need some hints how to do that. Maybe there is a template or an easy
function available.
I have a MySQL database with some tables. Everytime a table record
changes, I want also put the old record to a history database.
The history table and the original only differs that the key of the
original will be just a field in the backup, while the new key is now
the UNIX time stamp.
How can I do that "easy"?
Just write yourself a little update function, and add a insert call before
the actual update.
Here is a little update function that I use ($columns and $values get set in
a loop before):
function mysqlUpdate($table, $columns, $values, $criteria){
$sql = 'UPDATE '.$table.' SET ';
for($i = 0; $i < count($columns); $i++){
$sql .= $columns[$i].' = "'.$values[$i].'"';
if($i < count($columns) - 1){
$sql .= ', ';
}
}
$sql .= ' WHERE '.$criteria;
#debug($sql);
return mysql_query($sql);
}
Since you pass the $criteria (e.g. 'id = "23"') anyways, you can easily call
the record first, and copy it to another table.
--
Kind regards,
hochprior
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php