Php+mysql Transaction Rollback&commit Sample _php Tutorial

Source: Internet
Author: User
mysql_query ("Begin");//Start a transaction
mysql_query ("SET autocommit=0"); Set transaction not automatic commit
$insert = "INSERT INTO UserInfo VALUES (' aa12 ', ' AA ', ' 1 ', ' aaa ')";
mysql_query ($insert);
mysql_query ("commit");//non-autocommit mode, you must manually perform a COMMIT to make the operation effective
mysql_query ("SET autocommit=0");
$insert = "INSERT INTO UserInfo VALUES (' aa20 ', ' AA ', ' 1 ', ' aaa ')";
$insert = "INSERT INTO UserInfo VALUES (' aa8 ', ' AA ', ' 1 ')";
mysql_query ("COMMIT");
if (mysql_num_rows==0)
mysql_query ("ROLLBACK");//non-autocommit mode, execution ROLLBACK invalidates the transaction operation
else echo "OK";
mysql_query ("CLOSE");
mysql_query ("SET autocommit=1");//restore autocommit mode
$insert = "INSERT INTO UserInfo VALUES (' aa15 ', ' AA ', ' 1 ', ' aaa ')";
mysql_query ($insert);//Do not need to perform commit manually to take the transaction operation into effect

After the begin, it works with set autocommit=0, and after that setting set autocommit=0 or 1 o'clock is not valid. Therefore, to make the operation clear, the begin is generally not used.

http://www.bkjia.com/PHPjc/321129.html www.bkjia.com true http://www.bkjia.com/PHPjc/321129.html techarticle mysql_query ("Begin");//Start a transaction mysql_query ("Set autocommit=0");//SET Transaction not automatic commit $insert = "INSERT INTO UserInfo VALUES (' aa12 ', ' AA ', ' 1 ', ' AAA '); Mysql_query ($ ...

  • Related Article

    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.