MYSQL transaction control and rollback in php-php Tutorial

Source: Internet
Author: User
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 ();?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.