How to implement mysql transaction processing in php, phpmysql transaction processing_PHP tutorial

WBOY
Release: 2016-07-13 10:10:48
Original
840 people have browsed it

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.

www.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...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template