How to identify that which data are updated in sql / php?

Viewed 37

i am using 2 database one is for original and one is for backup. i want to only update those data in backup database whose value are update in main database, so how can i achieve this ?

for ex::: Main Database table : fruit Fruit name - qty Banana : 2 Apple : 15 cherry : 25

if quantity of Apple are updated to 13 than only the quantity of Apple will update on backup database instead of all fruit quantity update

1 Answers

Did you try to use triggers? I think that could be one solution cause you said you dont have any solution how to do it.

I tried this trigger and it worked for me. Before that I created 2 databases test and test_2, where both had same table fruit.

CREATE TABLE `fruit` (
    `name`varchar(255) DEFAULT NULL,
    `qty` int
);

And this is the trigger

use test;
delimiter $$
create trigger after_update_fruit_qty 
after update 
on test.fruit for each row
begin
    update test_2.fruit
    set qty = new.qty
    where name = new.name;
end;
$$
Related