MySQL cross-Library transaction XA

Source: Internet
Author: User
Tags rollback

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.