<?php
$mysqli=new mysqli("localhost","root","1234","test");
if($mysqli->connect_error){
die($mysqli->connect_error);
}
$mysqli->autocommit(false);
$sql1="update account set balance=balance-2 where id=1";
$sql2="update account set balance=balance+2 where id=2";
$b1=$mysqli->query($sql1);
$b2=$mysqli->query($sql2);
if(!$b1||!$b2){
echo "失败".$mysqli->error;
$mysqli->rollback();
}else{
echo "成功";
$mysqli->commit();
}
$mysqli->close();
?>
$mysqli=new mysqli("localhost","root","1234","test");
if($mysqli->connect_error){
die($mysqli->connect_error);
}
$mysqli->autocommit(false);
$sql1="update account set balance=balance-2 where id=1";
$sql2="update account set balance=balance+2 where id=2";
$b1=$mysqli->query($sql1);
$b2=$mysqli->query($sql2);
if(!$b1||!$b2){
echo "失败".$mysqli->error;
$mysqli->rollback();
}else{
echo "成功";
$mysqli->commit();
}
$mysqli->close();
?>