A period of time in the work encountered cross-Library transaction issues, and later on the online query, and now do a collation and summary.
1'%xa% '
= On
<?PHP$dbtest 1=NewMysqli ("172.20.101.17", "public", "public", "Dbtest1") or die("Dbtest1 Connection Failed");$dbtest 2=NewMysqli ("172.20.101.18", "public", "public", "Dbtest2") or die("Dbtest2 Connection Failed");//specifying a ID,XID for an XA transaction must be a unique value. $xid=uniqid("");//Two libraries specify the same transaction ID, indicating that the operations of the two libraries are in the same transaction$dbtest 1->query ("XA START"$xid‘");//Preparing transactions 1$dbtest 2->query ("XA START"$xid‘");//Preparing transactions 2Try { //$dbtest 1 $return=$dbtest 1->query ("UPDATE member SET name= ' Don Barley ' WHERE id=1") ; if($return==false) { Throw New Exception("library [email protected] Failed to perform update member operation! "); } //$dbtest 2 $return=$dbtest 2->query ("UPDATE memberpoints SET point=point+10 WHERE memberid=1") ; if($return==false) { Throw New Exception("library [email protected] Failed to perform update memberpoints operation! "); } //Phase 1: $dbtest 1 ready to commit $dbtest 1->query ("XA END"$xid‘"); $dbtest 1->query ("XA PREPARE"$xid‘"); //Phase 1: $dbtest 2 ready to commit $dbtest 2->query ("XA END"$xid‘"); $dbtest 2->query ("XA PREPARE"$xid‘"); //Phase 2: Submit two libraries $dbtest 1->query ("XA COMMIT"$xid‘"); $dbtest 2->query ("XA COMMIT"$xid‘");} Catch(Exception $e) { //Phase 2: rollback $dbtest 1->query ("XA ROLLBACK"$xid‘"); $dbtest 2->query ("XA ROLLBACK"$xid‘"); die($e-getMessage ());}$dbtest 1-close ();$dbtest 2-close ();?>
The performance of XA is very low. A database transaction and XA transactional performance comparisons between multiple databases can be found to be about 10 times times worse.
MySQL cross-Library transaction XA