<?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