<?php
//mysqli扩展库-事务控制account帐号表 balance余额
//1、创建mysql对象
$mysqli=new mysqli("127.0.0.1","root","password","testdb");
//验证是否连接成功
if($mysqli->connect_error){
die("连接失败".$mysqli->connect_error);
}
//将提交设为flase
$mysqli->autocommit(flase);
//2、操作数据库(发送sql语句)
$sql1="updata account set balance=balance-2 where id=1";
$sql2="updata account set balance=balance+2 where id=2";
$b1=$mysqli->query($sql1) ;
$b2=$mysqli->query($sql2) ;
if(!$b1||!$b2){
//回滚
echo"失败,启用回滚".die($mysqli->error);
$mysqli->rollback();
}else{
echo"成功";
//提交
$mysqli->commit();
}
//
$mysqli-close();
?>
mysqli扩展库操作mysql数据库事务控制roolback
最新推荐文章于 2021-03-18 04:12:09 发布