This article illustrates the method of PHP implementation of MySQL transaction processing. Share to everyone for your reference. The specific analysis is as follows:
The condition for this feature is that the environment MySQL 5.2/php 5 supports the Transaction table type. Need to InnoDB, with these conditions you can do the above implementation, this thing roll back operation is a big project often used, such as banks, E-commerce and so will use, there is a need for friends can refer to.
Recent project software upgrades to support transaction processing, make an example for everyone to learn reference.
Environment MySQL 5.2/php 5
The table type that supports transactions requires InnoDB
PHP MySQL transaction processing implementation code is as follows:
Copy Code code as follows:
? Php
$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 ());
$ssql 1= "INSERT into pf_item values (' 22 ', ' we ', ' 30 ')"; Execute SQL 1
if (!mysql_query ($ssql 1)) {
echo $ssql 1.mysql_errno (). ":". Mysql_error (). <br> ";
mysql_query (' ROLLBACK ') or exit (Mysql_error ());//Determine rollback when execution fails
Exit
}
$ssql 1= "INSERT into pf_item values (', ' hell ', ' 10 ')"; Execute SQL 2
if (!mysql_query ($ssql 1)) {
echo $ssql 1.mysql_errno (). ":". Mysql_error (). <br> ";
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 help you with your PHP program design.