This topic is locked

Backing up a registry before updating it

12/20/2020 1:31:28 AM
PHPRunner General questions
A
alfonso authorDevClub member

I have a table A with my clients. A table B where they are registered in another service. And a copy A_backup table of the records of the first.
When a person is registered in table B (add record) then, from the "Before add" event, we search in table A if that record exists. (there is a unique field that is the DNI or VAT)
If the record that we are going to save in table B does not exist in table A, then we add it to table A. Simple. No problem
If the record that we are going to save in table B already exists in table A, then we replace the data with an update. There is no problem either.
What I want to do and I do not know how is that if the record exists we can do, before the Update to table A a backup copy of that record that is in table A in table A_backup
Sure it's easy, but I don't know how to do it. Thank you

M
MikeT 12/20/2020

I'm not sure about the prupose of Table_A, but if understand correctly I'd simply triggers the database in table A both for before insert and before update. These triggers then automatically write the new (insert( or previous (update) records to tha backup table.

A
alfonso authorDevClub member 12/21/2020

How can I do it? In Before add events of Table A?

M
MikeT 12/21/2020



How can I do it? In Before add events of Table A?


Not in phprunner, triggers are defined in the database. Look it up in the documentation of your database. Can be created very easily with SQL-synthax.

Sergey Kornilov admin 12/21/2020

You can either use database triggers or use BeforeEdit event for that purpose.
https://xlinesoft.com/phprunner/docs/before_record_updated.htm

In BeforeEdit event $oldvalues array contains the data of the record before the change so you can save it in another table.