Get the App
SLTechnology News&Howtos  ›  Development  › 

Analysis of php mysql transaction rollback operation

Shulou Source: shulou.com Published: 2022-06-03 13:09:44 11月14日 Update

This article mainly introduces "php mysql transaction processing rollback operation analysis", in daily operation, I believe many people have doubts on php mysql transaction processing rollback operation analysis, Xiaobian consulted all kinds of information, sorted out simple and easy to use operation methods, hope to answer "php mysql transaction processing rollback operation analysis" doubts helpful! Next, please follow the small series to learn together!

A lot of novice in the project process, will encounter such a situation, such as: forum coin deduction project, when the user pays forum coin if suddenly cut off the network, computer crash, power failure, and other natural disasters, resulting in the transaction did not succeed (that is, the user's coin has been deducted, but there is no consumption record in the server database and other circumstances), how should this situation be handled?

At this point, we can use Mysql transaction rollback to process, then how to write the code?

Then let me talk about how to deal with the rollback of mysql transactions.

First of all, only INNODB and BDB data tables in MYSQL can support transaction processing! Other types are not supported!

What if our data table already exists and is not one of the two types mentioned above?

1, I can find a software called MySQL-Front, which can change the table type.

2, we can also change through SQL statements, SQL statements can be written like this:

The copy code is as follows:

ALTER TABLE TABLENAME type = InnoDB;

After changing all the tables that need to be fixed, we can test them with code in PHP files.

The copy code is as follows:

mysql_query("BEGIN"); //or mysql_query("START TRANSACTION");

$sql = "INSERT INTO ... ";

$sql2 = "INSERT INTO ... ";

$res = mysql_query($sql);

$res1 = mysql_query($sql2);

if($res && $res1){

mysql_query("COMMIT");

echo 'submitted successfully. ';

}else{

mysql_query("ROLLBACK");

echo 'data rollback. ';

}

mysql_query("END");

At this point, the study of "php mysql transaction processing rollback operation analysis" is over, hoping to solve everyone's doubts. Theory and practice can better match to help everyone learn, go and try it! If you want to continue learning more relevant knowledge, please continue to pay attention to the website, Xiaobian will continue to strive to bring more practical articles for everyone!

Tags: Processing transaction code type data learning situation success datasheet time more users forums statements projects help support utility and then natural disasters Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info NVidia Shulou Technology Docker Microsoft