In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
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!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.