After starting a transaction in PHP, the program throws an exception without executing a commit and not executing the rollback MySQL transaction will be rolled back?

Source: Internet
Author: User
Some people on the internet say that SQL statement execution error or program error after opening a transaction without executing rollback, the next run will automatically commit
Program error does not roll back rollback

However, some people say that throwing exceptions and other programs if MySQL does not have committed transactions, then the autocommit automatically submit the parameters should be 0.
However, if you use the MySQL driver in other languages, these drivers generally have the function of auto-recovery autocommit, which will automatically ROLLBACK the transaction that is not processed after the request processing is completed.

Reply content:

Some people on the internet say that SQL statement execution error or program error after opening a transaction without executing rollback, the next run will automatically commit
Program error does not roll back rollback

However, some people say that throwing exceptions and other programs if MySQL does not have committed transactions, then the autocommit automatically submit the parameters should be 0.
However, if you use the MySQL driver in other languages, these drivers generally have the function of auto-recovery autocommit, which will automatically ROLLBACK the transaction that is not processed after the request processing is completed.

I think you're using PDO here by default.
This is what the official document says:

When the script ends or when a connection was about to being closed, if you had an outstanding transaction, PDO would automati Cally roll it back. This was a safety measure to help avoid inconsistency in the cases where the script terminates unexpectedly--if you didn ' t Explicitly commit the transaction, then it's assumed that something went awry and so the rollback was performed for the Safet Y of your data.
When the script ends or when a connection are about to be closed

This means that when the script ends (including the normal end or the end of the exception).

PDO would automatically roll it back

PDO is automatically rolled back.
The documentation has been made very clear.
If you are not using the PDO driver, you can view the relevant driver documentation, or make clear what drivers are used in the issue.

Incidentally, the previous mysql_connect () function was not recommended for re-use (was deprecated).

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