This article mainly introduces the example of transaction usage in PHP. This article provides the simplest entry-level instance. For more information, see
<? Php // database connection $ conn = mysql_connect ('localhost', 'root', ''); mysql_select_db ('test', $ conn ); mysql_query ("set names gbk");/* tables that support transactions must be InnoDB-type. a TRANSACTION can only appear once: mysql_query ('Start transaction '); // start the transaction mysql_query ('rollback'); // roll back the transaction mysql_query ('commit '); // submit the transaction. if multiple ROLLBACK transactions occur in a transaction, when a transaction is committed, all operations on the database are canceled before the first rollback and after the transaction starts. after the first rollback, all operations on the database remain valid until the transaction is committed, therefore, the rollback statement is generally placed only before the transaction statement is submitted. if a transaction does not have a commit statement, all the following operations on the database are executed at the start of the transaction (the execution method returns the right or wrong ), but it has no impact on the database, but in the lower part of the execution When starting a TRANSACTION statement, the previous TRANSACTION will automatically submit */mysql_query ('Start transaction'); $ isBad = 0; $ ins_testTable1 = "insert into testtable1 (NAME, age) VALUES ('first', 23) "; if (! Mysql_query ($ ins_testTable1) {$ isBad = 1;} // An error occurred while inserting the statement Field NAME $ ins_testTable2 = "insert into testtable1 (NAME, ages) VALUES ('second ', '24') "; if (! Mysql_query ($ ins_testTable2) {$ isBad = 1;} if ($ isBad = 1) {echo $ isBad; mysql_query ('rollback ');} mysql_query ('commit '); mysql_close ($ conn);?>