Home  >  Article  >  Backend Development  >  mysqli执行mysql事务的有关问题

mysqli执行mysql事务的有关问题

WBOY
WBOYOriginal
2016-06-13 11:33:14900browse

mysqli执行mysql事务的问题

<br />	public static function exec_sql_tran($arr_sql){<br />		$result=true;<br />		$con = new MySQLi(DBHOST,DB_USER,DB_PASSWD,DB_NAME);<br />		$con->autocommit(FALSE);<br />	 	foreach($arr_sql as $key=>$sql){<br />			if (!$con->query($sql)) {<br />				echo $con->error."<br>/";<br />				$resulf=false;<br />				$con->rollback();<br />                                break;<br />			}<br />		}<br />		print_r($result);<br />		if($result){<br />			$con->commit();<br />		}<br />		else{<br />			$con->rollback();<br />		}<br />		$con->close();<br />	}<br />

$arr_sql是一个存储数据库代码的数组
我测试的时候写了两个insert的句子,第一个句子正确,第二个句子错误,当时执行下来总是发现第一个句子执行成功。
好像事务没用一样,php新手,求教了

事务
Statement:
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