Home > Backend Development > PHP Tutorial > PHP事务的怎么写

PHP事务的怎么写

WBOY
Release: 2016-06-13 11:26:38
Original
986 people have browsed it

PHP事务的如何写?
PHP 的事务怎么写? 我现在是一条update,一条insert
代码如下,错误是,值类型发生了错误,事务没起作用.

$db = new DbManager();<br />	$conn = $db->getConnection();<br />	$conn->set_charset("utf8");<br />	<br />	if(mysqli_connect_errno())<br />	{<br />		echo 'error connect database! please content manager!';<br />		exit;<br />	}<br />	//echo connection_status();<br />	$tbNums = explode(',',$tbNum);<br />	<br />	$conn->autocommit(FALSE);<br />	$flag = true;<br />	$a=0;<br />	foreach($tbNums as $key => $value)<br />	{<br />		$updateBalance = "UPDATE T_SMS_TBNUM SET STATUS = 2 WHERE ID = ?";<br />		$insertRelate = "INSERT INTO T_SMS_TBNUMRELATE (TBID,OWNCLIENTID,REALFEE,CREATETIME) VALUES(?,?,?,?)";<br />		<br />		<br />		$stmtUpdateClient = $conn->prepare($updateBalance);<br />		$stmtUpdateClient->bind_param('i',$value);<br />		$ss = $stmtUpdateClient->execute();<br />		<br />		$stmt = $conn->prepare($insertRelate);<br />		$foura = 4;<br />		$a++;<br />		if($a!=0){<br />			$value = 's';<br />		}<br />		$stmt->bind_param('iids',$value,$clientId,$foura,date('Y-m-d H:i:s'));<br />		$boooo = $stmt->execute();<br />		echo $ss.'+'.$boooo;<br />		if($stmtUpdateClient->affected_rows <= 0 || $stmt->affected_rows <= 0)<br />		{<br />			echo $stmtUpdateClient->affected_rows.'|'.$stmt->affected_rows;<br />			$flag = false;<br />			break;<br />		}<br />	}<br />		if(!$flag)<br />		{<br />			$conn ->rollback();<br />			$conn -> autocommit(TRUE);<br />			$conn->close();<br />			return 'paylog false!';<br />		}else<br />		{<br />			$conn->commit();<br />			$conn -> autocommit(TRUE);<br />			$conn->close();<br />			return '1';<br />		}
Copy after login

Related labels:
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