这三个东西如何搭配使用呢

WBOY
Release: 2016-06-23 13:45:03
Original
1041 people have browsed it

$_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();
Copy after login
Copy after login

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();
Copy after login
Copy after login


结构很清晰。
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template