Php+mysqli Transaction Transfer problem instance, MYSQLI transaction processing
In this paper, we describe the method of Php+mysqli using transaction processing transfer problem. Share to everyone for your reference. The implementation method is as follows:
<?php header ("content-type:text/html; Charset=utf-8 "); $mysqli = new Mysqli ("localhost", "root", "064319", "PHP"); $mysqli->set_charset ("UTF8"); if ($mysqli->connect_errno) {die (' Database connection failed '. $mysqli->connect_error); } $mysqli->autocommit (false); The auto-commit mode is set to false $flag = true; Flag that 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 ' transfer success '; } else {$mysqli->rollback (); Echo ' transfer failed '; } $mysqli->autocommit (true); Reset transaction to Auto-commit $mysqli->close ();?;
I hope this article is helpful to everyone's PHP programming.
http://www.bkjia.com/PHPjc/957138.html www.bkjia.com true http://www.bkjia.com/PHPjc/957138.html techarticle php+mysqli using transaction processing transfer problem instance, MYSQLI transaction processing This paper describes the Php+mysqli method of transaction transfer problem. Share to everyone for your reference. Concrete Reality ...