Home >Backend Development >PHP Tutorial >Parsing php mysql transaction processing rollback operation (with examples)_PHP tutorial
Many novices will encounter such a situation during the project process, such as: in the forum currency deduction project, if the user suddenly disconnects from the Internet, computer crashes, power outage, and other natural disasters when paying forum coins, resulting in This transaction was unsuccessful (that is, the user's coins have been deducted, but there are no consumption records in the server database, etc.). How should this situation be handled?
At this time, we can use Mysql transaction rollback to process it. How to write the code?
Then let me talk about how to handle this mysql transaction rollback.
First of all, only INNODB and BDB type 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 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 it through SQL statements. The sql statements can be written like this:
$sql = "INSERT INTO ...";
$sql2 = "INSERT INTO ...";
$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");