Php implementation and release at the same time I want to make a form submission function to publish the submitted data to three databases at the same time. how can I implement the code ?, This is my stupid method. the implementation of INSERTINTOTABLE1 (A, B, C) VALUES ($ A, $ B, $ C) INSERTINTOTABLE2 (A, B, C) VALUES (php is released at the same time.
I want to create a form submission function to publish the submitted data to three databases at the same time. how can I implement the code?
------ Solution --------------------
This is my dummies.
Insert into TABLE1 (A, B, C) VALUES ($ A, $ B, $ C)
Insert into TABLE2 (A, B, C) VALUES ($ A, $ B, $ C)
Insert into TABLE3 (A, B, C) VALUES ($ A, $ B, $ C)
------ Solution --------------------
There are two solutions 1. if the three databases are three servers, you can set the master-slave synchronization database.
2. if it is three databases of the same database, you may wish to make a simple internal interface. the Source program will not post data to this interface to let this interface complete database insertion!
------ Solution --------------------
SQL code
Acquire mutexcon1: START TRANSACTIONcon1: INSERTcon2: START TRANSACTIONcon2: INSERTcon3: START TRANSACTIONcon3: rows = con1 insert OK & con2 insert OK & con3 insert okif (flag) {con1: COMMIT con2: COMMIT con3: COMMIT} else {con1: ROLLBACK con2: ROLLBACK con3: ROLLBACK} release mutex