Parse the phpmysql transaction processing rollback operation (attached with an instance ). Many new users may encounter such a situation during the project process, such as the coin deduction project in the forum, when a user pays for the Forum currency, if the network is suddenly disconnected, the computer crashes, the power is cut off, and many other new users encounter such a situation during the project, for example, in the forum currency deduction project, when a user makes a payment for the Forum currency, if the network is suddenly disconnected, the computer crashes, power outages, and other natural disasters, the transaction fails (that is, the user's currency has been deducted, but there are no consumption records in the server database and other situations). how should we handle this situation?
At this time, we can use Mysql transaction rollback for processing. how can we write the code?
Now let me talk about how to handle the mysql transaction rollback.
First, only INNODB and BDB data tables in MYSQL can support transaction processing! Other types are not supported!
What should we do if our data table already exists and is not the two types mentioned above?
1. I can find a software named MySQL-Front, which can change the table type.
2. you can also use SQL statements to modify the statement. The SQL statement can be written as follows:
The code is as follows:
Alter table tablename type = InnoDB;
After changing all the tables to be repaired, we can use the code in the PHP file for testing.
The code is as follows:
Mysql_query ("BEGIN"); // or mysql_query ("start transaction ");
$ SQL = "INSERT ...";
$ Sql2 = "insert ...";
$ Res = mysql_query ($ SQL );
$ Res1 = mysql_query ($ sql2 );
If ($ res & $ res1 ){
Mysql_query ("COMMIT ");
Echo 'submission successful. ';
} Else {
Mysql_query ("ROLLBACK ");
Echo 'data rollback. ';
}
Mysql_query ("END ");
Here, we should know how to use PHP to handle mysql transaction rollback. Easy!
...