PHP事务的怎么写

WBOY
发布: 2016-06-13 11:26:38
原创
955 人浏览过

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 />		}
登录后复制

相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板