php+mysqli example of transaction transfer with transactions

Source: Internet
Author: User

In this paper, we describe the method of Php+mysqli using transaction processing transfer problem. Share to everyone for reference

<?PHP/**php+mysqli Using Transaction Transfer Problem Example * Author http://www.lai18.com * Date 2015-04-19 * Version 1 **/  Header("content-type:text/html; Charset=utf-8 "); $mysqli=NewMysqli ("localhost", "root", "064319", "PHP"); $mysqli->set_charset ("UTF8"); if($mysqli-Connect_errno) {     die(' Database connection failed '.$mysqli-connect_error); }      $mysqli->autocommit (false);//Auto-commit mode set to False$flag=true;//flag of whether the transaction was executed successfully     $query= "Update account set balance=balance-1000 where id=3"; $result=$mysqli->query ($query); $affected _count=$mysqli-affected_rows; if(!result | |$affected _count= = 0) {//failed$flag=false; }      $query= "Update account set balance=balance+1000 where id=2"; $result=$mysqli->query ($query); $affected _count=$mysqli-affected_rows; if(!$result||$affected _count= = 0) {    $flag=false; }      if($flag) {    $mysqli-commit (); Echo' Successful transfer '; } Else {    $mysqli-rollback (); Echo' Transfer failed '; }      $mysqli->autocommit (true);//Reset transaction to Auto commit$mysqli-close ();?>

Reference Source:
php+mysqli example of transaction transfer with transactions
Http://www.lai18.com/content/368652.html

php+mysqli example of transaction transfer with transactions

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.