Home > Article > Backend Development > A brief analysis of the solution to Mysql data rollback error_PHP tutorial
There are two main methods of transaction processing in MYSQL.
1. Use begin, rollback, and commit to implement
begin starts a transaction
rollback transaction rollback
commit transaction confirmation
2. Use set directly to change the automatic submission mode of mysql
MYSQL automatically submits by default, that is, if you submit a QUERY, it will be executed directly! We can implement transaction processing by
set autocommit=0 to disable automatic submission
set autocommit=1 and enable automatic submission
.
When you use set autocommit=0, all your subsequent SQL will be processed as transactions until you confirm with commit or rollback.
Note that when you end this transaction, you also start a new transaction! According to the first method, only the current one is used as a transaction!
I personally recommend using the first method!
Only INNODB and BDB type data tables in MYSQL can support transaction processing! Other types are not supported!
***: Generally, the default engine of MYSQL database is MyISAM. This engine does not support transactions! If you want MYSQL to support transactions, you can modify it manually:
The method is as follows:
1. Modify the c:appservmysqlmy.ini file, find skip-InnoDB, add # in front, and save the file.
2. Enter: services.msc during operation to restart the mysql service.
3. Go to phpmyadmin, mysql->show engines; (or execute mysql->show variables like 'have_%';), check InnoDB for YES, which means the database supports InnoDB.
This means that transaction transactions are supported.
4. When creating a table, you can select the InnoDB engine for the Storage Engine. If it is a previously created table, you can use mysql->alter table table_name type=InnoDB;
or mysql->alter table table_name engine=InnoDB; to change the engine of the data table to support transactions.
/*Method 1*/