首页 > 后端开发 > php教程 > PHP事务的如何写?

PHP事务的如何写?

WBOY
发布: 2016-06-23 14:13:44
原创
956 人浏览过

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

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


回复讨论(解决方案)

if( $stmt->affected_rows <= 0 ||  ($masterId && $stmtLower->affected_rows <= 0))		{					$conn ->rollback();					$conn -> autocommit(TRUE);					$conn->close();			return 'unknow_error';		}else		{					$conn->commit();					$conn -> autocommit(TRUE);					$conn->close();			return '1';		}
登录后复制

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