Some people on the Internet say that after opening a transaction, the SQL statement execution error or program error occurs. If rollback is not executed, the next run will automatically commit
Program error will not rollback rollback
But some people say that exceptions are thrown. If MySQL has an uncommitted transaction, then the AUTOCOMMIT automatically submitted parameter should be 0 at this time.
However, if you operate through MySQL drivers in other languages, these drivers generally have the function of automatically recovering AUTOCOMMIT. After the request processing is completed, unprocessed transactions will be automatically ROLLBACKed.
Some people on the Internet say that after opening a transaction, the SQL statement execution error or program error occurs. If rollback is not executed, the next run will automatically commit
Program error will not rollback rollback
But some people say that exceptions are thrown. If MySQL has uncommitted transactions, the AUTOCOMMIT automatically submitted parameter should be 0 at this time.
However, if you operate through MySQL drivers in other languages, these drivers generally have the function of automatically recovering AUTOCOMMIT. After the request processing is completed, unprocessed transactions will be automatically ROLLBACKed.
Here I assume by default that you are using PDO.
The official document says this:
When the script ends or when a connection is about to be closed, if you have an outstanding transaction, PDO will automatically roll it back. This is 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 is assumed that something went awry, so the rollback is performed for the safety of your data.
When the script ends or when a connection is about to be closed
It means that when the script ends (including normal end or abnormal end).
PDO will automatically roll it back
PDO will automatically roll back.
The document has made it very clear.
If you are not using the PDO driver, you can check the relevant driver documentation, or state clearly what driver you are using in the question.
By the way, the previous mysql_connect() function is officially no longer recommended (was deprecated).