How to implement mysql transaction processing in php, phpmysql transaction processing
The example in this article describes the method of implementing mysql transaction processing in PHP. Share it with everyone for your reference. The specific analysis is as follows:
The prerequisite for realizing this function is that the environment mysql 5.2/php 5 supports transaction table types and requires InnoDB. With these conditions, you can implement the above. This transaction rollback operation is often used in large projects. , will be used in banks, e-commerce, etc. Friends in need can refer to it.
Recently, the project software has been upgraded to support transaction processing. Here is an example for everyone to learn and refer to.
Environment mysql 5.2 /php 5
Table type that supports transactions requires InnoDB
php mysql transaction processing implementation program code is as follows:
Copy code The code is as follows:
$LinkID =mysql_connect('localhost:3307','root',*******);
mysql_select_db('web_his',$LinkID);
mysql_query("set names utf8");
/* Create transaction */
mysql_query('START TRANSACTION') or exit(mysql_error());
$ssql1="insert into pf_item values('22','we','30')"; //Execute sql 1
if(!mysql_query($ssql1)){
echo $ssql1.mysql_errno().":".mysql_error()."
";
Mysql_query('ROLLBACK') or exit(mysql_error());//Determine rollback when execution fails
exit;
}
$ssql1="insert into pf_item values('21','hell','10')"; //Execute sql 2
if(!mysql_query($ssql1)){
echo $ssql1.mysql_errno().":".mysql_error()."
";
Mysql_query('ROLLBACK') or exit(mysql_error()); // Determine rollback when execution fails
exit;
}
mysql_query('COMMIT') or exit(mysql_error());//Execute transaction
mysql_close($LinkID);
?>
I hope this article will be helpful to everyone’s PHP programming design.
http://www.bkjia.com/PHPjc/932486.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/932486.htmlTechArticleHow to implement mysql transaction processing in php, phpmysql transaction processing This article describes the method of implementing mysql transaction processing in php. Share it with everyone for your reference. The specific analysis is as follows: To achieve...