How to write PHP transactions? How to write PHP & nbsp; transactions? & Nbsp; I am an update. the insert code is as follows. the error is that the value type is incorrect and the transaction does not work. $ db & nbsp ;=& nbsp; new & nbsp; DbManager (); $ conn & nbsp ;=& nbsp; $ db-& gt; how to write the getC PHP transaction?
How to write PHP transactions? I am an update and an insert
The code is as follows. the error is that a value type error occurs and the transaction does not work.
$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';
}
Share:
------ Solution --------------------
If ($ stmt-> affected_rows <= 0
------ Solution --------------------
($ 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 ';
}