MYSQL transaction control and rollback in php
Connect_error) {die ($ mysqli-> connect_error);} // because the system commits data by default in transaction commit, set this parameter to FALSE. do not submit $ mysqli-> autocommit (false) first ); // In fact, the system has already made a save point here to record all the statuses at this time. rollback is here to roll back. // $ mysqli-> savepoint; // write the database operation statement $ sql1 = "insert into table name (field name) values (field value )"; $ sql2 = "update table name set field name = value where condition"; $ sql3 = "delete from table name where condition "; // execute the SQL statement $ res1 = $ mysqli-> query ($ sql1) or die ($ mysqli-> error); $ res2 = $ mysqli-> query ($ sql2) or die ($ my Sqli-> error); $ res3 = $ mysqli-> query ($ sql3) or die ($ mysqli-> error); // You can check whether all tasks are successfully executed. if (! $ Res1 |! $ Res2 |! $ Res3) {// roll back if one fails. if you set a rollback point, such as, add parameter a to roll back to location a $ mysqli-> rollback ();} else {// submit $ mysqli-> commit ();} // close the resource $ musqli-> close ();?>