The following describes how to solve the Mysql data rollback error. You can refer to the following two methods for MYSQL transaction processing. 1. Use begin, rollback, and commit to start a transaction rollback transaction to roll back the commit transaction confirmation. 2. directly use set to change the mysql automatic commit mode. MYSQL automatically commits by default, that is, if you submit a QUERY, It will be executed directly! We can use set autocommit = 0 to disable automatic commit. set autocommit = 1 to enable automatic commit to process transactions. When you use set autocommit = 0, all your SQL statements will be processed as transactions until you use commit to confirm or roll back. Note that a new transaction is also started when you end the transaction! In the first method, only the current transaction is used! The first method is recommended! In MYSQL, only INNODB and BDB Data Tables support transaction processing! Other types are not supported! * **: The default MYSQL database engine is MyISAM, which does not support transactions! If you want MYSQL to support transactions, You can manually modify them as follows: 1. modify c: \ appserv \ mysql \ my. INI file, locate skip-InnoDB, add # to the front, and save the file. 2. Enter services. msc in the running state to restart the mysql service. 3. in phpmyadmin, mysql-> show engines; (or execute mysql-> show variables like 'have _ % ';). If InnoDB is YES, InnoDB is supported. This means that transaction is supported. 4. When creating a table, you can select the InnoDB Engine for the Storage Engine. For tables created earlier, you can use mysql-> alter table table_name type = InnoDB; or mysql-> alter table table_name engine = InnoDB; to change the data table engine to support transactions.
/* Method 1 * // **************** transaction -- 1 *************** /$ conn = mysql_connect ('localhost ', 'root', 'root') or die ("data connection Error !!! "); Mysql_select_db ('test', $ conn); mysql_query (" set names 'gbk' "); // use GBK Chinese encoding; // START a TRANSACTION mysql_query ("BEGIN"); // or mysql_query ("start transaction"); $ SQL = "INSERT INTO 'user' ('id ', 'username', 'sex ') VALUES (NULL, 'test1', '0') "; $ sql2 =" insert into 'user' ('did', 'username ', 'Sex ') VALUES (NULL, 'test1', '0') "; // The error code $ res = mysql_query ($ SQL) is written on purpose ); $ res1 = mysql_query ($ sql2); if ($ res & $ res1) {mysql_query ("COMMIT"); echo 'submitted successfully. ';} Else {mysql_query ("ROLLBACK"); echo' data ROLLBACK. ';} Mysql_query ("END "); /* method 2 ************** * ***/mysql_query ("set autocommit = 0 "); // If mysql is not automatically submitted, you must use the commit statement to submit $ SQL = "INSERT INTO 'user' ('id', 'username', 'sex') VALUES (NULL, 'test1', '0') "; $ sql2 =" insert into 'user' ('did', 'username', 'sex') VALUES (NULL, 'test1 ', '0') "; // The error $ 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"); // do not forget mysql_query ("set autocommit = 1") after the transaction is processed; Submit automatically