Re: backup of database record before update

From: Date: Tue, 30 Oct 2007 19:15:55 +0000
Subject: Re: backup of database record before update
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-44275@lists.php.net to get a copy of this message
At 06:57 28/10/2007, you wrote:
Message-ID: <4724328C.90608@elmit.com> Date: Sun, 28 Oct 2007 14:56:12 +0800 From: Ronald Wiplinger <ronald@elmit.com> 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"?
"Easy" is to set a MySQL5 trigger which does the Insert on update : http://dev.mysql.com/doc/refman/5.0/en/triggers.html eg (from the manual page) : DELIMITER | CREATE TRIGGER testref BEFORE INSERT ON test1 FOR EACH ROW BEGIN
    INSERT INTO test2 SET a2 = NEW.a1;
    DELETE FROM test3 WHERE a3 = NEW.a1;
    UPDATE test4 SET b4 = b4 + 1 WHERE a4 = NEW.a1;
END; | HTHCheers - Neil

« previous php.db (#44275) next »