The condition for implementing this function is that the table type that the Environment mysql 5.2/php 5 supports transactions needs InnoDB. 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, you can 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 Code is as follows: |
Copy code |
|
<? 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 (). "<br> ";
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 (). "<br> ";
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 );
?> |