Php implements mysql transaction processing and phpmysql transaction processing. Php implements mysql transaction processing. phpmysql transaction processing this article describes how php implements mysql transaction processing. Share it with you for your reference. The specific analysis is as follows: to implement php to implement mysql transaction processing, phpmysql transaction processing
This example describes how to implement mysql transaction processing in php. Share it with you for your reference. The specific analysis is as follows:
To implement this function, the condition is that mysql 5.2/php 5 supports the transaction table type, and InnoDB is required. with these conditions, you can implement the above, this rollback operation is often used by large projects, such as banks and e-commerce. if you need it, please refer to it.
Recently, the project software has been upgraded to support transaction processing. An example is provided for your reference.
Environment mysql 5.2/php 5
InnoDB is required for table types that support transactions.
The php mysql transaction processing implementation program code is as follows:
The code is as follows:
<? PHP
$ LinkID = mysql_connect ('localhost: 100', 'root ',*******);
Mysql_select_db ('web _ his ', $ LinkID );
Mysql_query ("set names utf8 ");
/* Create a transaction */
Mysql_query ('Start transaction') or exit (mysql_error ());
$ Ssql1 = "insert into pf_item values ('22', 'Ours ', '30')"; // execute SQL 1
If (! Mysql_query ($ ssql1 )){
Echo $ ssql1.mysql _ errno (). ":". mysql_error ()."
";
Mysql_query ('rollback') or exit (mysql_error (); // determines whether to roll back when execution fails.
Exit;
}
$ Ssql1 = "insert into pf_item values ('21', 'hangel', '10')"; // execute SQL 2
If (! Mysql_query ($ ssql1 )){
Echo $ ssql1.mysql _ errno (). ":". mysql_error ()."
";
Mysql_query ('rollback') or exit (mysql_error (); // determines whether to roll back when execution fails.
Exit;
}
Mysql_query ('commit ') or exit (mysql_error (); // execute the transaction
Mysql_close ($ LinkID );
?>
I hope this article will help you with php programming.
Examples in this article describes how to implement mysql transaction processing in php. Share it with you for your reference. The specific analysis is as follows...