MYSQLI Transaction Processing Demo

Source: Internet
Author: User

<?php $mysqli =new mysqli ("localhost", "root", "123456", "xsphpdb");

Turn off transaction processing $mysqli->autocommit (0);

$error =true;

$price = 50;

$sql = "Update zh set ye=ye-{$price} where name= ' Zhangsan '"; $result = $mysqli->query ($sql);

if (! $result) {$error =false;  echo "From Zhang three turn out failure <br>";    }else{if ($mysqli->affected_rows==0) {$error =false;    Echo "Zhang San's money has not changed";   }else{echo "from the Zhang San account transfer success!<br>"; }  }

$sql = "Update zh set ye=ye+{$price} where name= ' Lisi1 '";

$result = $mysqli->query ($sql);

if (! $result) {$error =false;  echo "Transfer from John Doe to failure <br>";    }else{if ($mysqli->affected_rows==0) {$error =false;    echo "John Doe's money has not changed";   }else{echo "to Li four account into the success of!<br>"; }  }

if ($error) {echo "Transfer succeeded!";  $mysqli->commit ();   }else{echo "Transfer failed!";  $mysqli->rollback (); }

$mysqli->autocommit (1);//Turn on transaction processing $mysqli->close () after completion;

MYSQLI Transaction Processing Demo

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.