Heim > Artikel > Backend-Entwicklung > 这三个东西如何搭配使用呢
$_mysqli->rollback();
$_mysql->atuocommit();
和 InnoDB如何使用
http://php.net/manual/zh/mysqli.autocommit.php 善用手册
一个小例子
$mysqli=new mysqli("localhost","root","123456","test"); if($mysqli->connect_error){ die($mysql->connect_error); } //将提交设为 false(一旦提交,无法回滚) $mysqli->autocommit(false); //保存点 ,把当前记录保存 $sql1="update account set balance=balance-1 where id=1"; $sql2="update account set balance=balance+1 where id=2"; $b1=$mysqli->query($sql1); $b2=$mysqli->query($sql2); if(!$b1||!$b2){ //回滚 $mysqli->rollback(); echo "失败--".$mysqli->error; }else{ //提交 $mysqli->commit(); echo "成功"; } $mysqli->close();
http://php.net/manual/zh/mysqli.autocommit.php 善用手册
一个小例子
$mysqli=new mysqli("localhost","root","123456","test"); if($mysqli->connect_error){ die($mysql->connect_error); } //将提交设为 false(一旦提交,无法回滚) $mysqli->autocommit(false); //保存点 ,把当前记录保存 $sql1="update account set balance=balance-1 where id=1"; $sql2="update account set balance=balance+1 where id=2"; $b1=$mysqli->query($sql1); $b2=$mysqli->query($sql2); if(!$b1||!$b2){ //回滚 $mysqli->rollback(); echo "失败--".$mysqli->error; }else{ //提交 $mysqli->commit(); echo "成功"; } $mysqli->close();