首页  >  文章  >  后端开发  >  PHP事务的怎么写

PHP事务的怎么写

WBOY
WBOY原创
2016-06-13 11:26:38954浏览

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 />		}

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn