Do you need to restore autocommit=1 when the MySQL transaction is complete?

Source: Internet
Author: User
Set autocommit = 0; Turn off auto-commit
Start transaction; Open a transaction;
---------------------......
Commit formally submit a transaction;


After commit, do you want to restore set autocommit = 1? I see no one else's case is restored, the commit will automatically recover?


Reply to discussion (solution)

Don't need
Because you typically do not perform multiple transaction operations in one program code
Even if it is, it's in your hands.
The connection is broken and the settings are automatically deactivated.

Don't need
Because you typically do not perform multiple transaction operations in one program code
Even if it is, it's in your hands.
The connection is broken and the settings are automatically deactivated.



Still not quite understand:
1.PHP a script that instantiates a DB class once, assuming that the DB object executes 100 commands in the script,
Does he automatically disconnect the connection after executing one command at a time? Or are you always using the same connection? Should not be resumed automatically submitted;

Autocommit default is 1, which commits transactions automatically

You set autocommit =0 to turn off autocommit, apparently this is your personal behavior
So after the end of the transaction, is it necessary to restore autocommit to 1, which is naturally your personal behavior

You just reconnect to the database, autocommit is still 1, regardless of the state of your last operation. This is the server's behavior.

If you were to execute 100 more transactions after a transaction, would you like to shut down or turn on the automatic commit of the transaction?

  • 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.