<?php
error_reporting(E_ALL^E_NOTICE);
header('content-type:text/html;charset=utf-8');
$mysqli=new mysqli('localhost', 'root', 'root', 'info');
if($mysqli->connect_errno){
die($mysqli->connect_error);
}
$mysqli->set_charset('utf8');
$mysqli->autocommit(FALSE);//关闭自动提交
$sql="UPDATE1 account SET money=money-200 WHERE username='king';";
$res=$mysqli->query($sql);
$res_affect=$mysqli->affected_rows;
$sql1='UPDATE account SET money=money+200 WHERE username="queen";';
$res1=$mysqli->query($sql1);
$res1_affect=$mysqli->affected_rows;
if($res && $res_affect>0 && $res1 && $res1_affect>0){
$mysqli->commit();
echo '转账成功<br/>';
$mysqli->autocommit(TRUE);
}else{
$mysqli->rollback();
echo '转账失败<br/>';
}
$mysqli->close();