What happens when an exception or crash occurs during a transaction?


If during a database transaction (after $pdo->beginTransaction) a fatal exception is thrown (but not a PDOException), what happens? Is the transaction rolled back automatically, or is it left open indefinitely?

Is the answer the same if there is a crash during a transaction?

I am worried about having rows locked indefinitely or leaving connections open indefinitely.

Using MySQL and PDO.


Transactions are rolled back when the connection to the db is closed and the connection is automatically closed whenever the PHP script ends, also when fatal errors occur. No need to worry about connections or transactions being open indefinitely.


Thanks for the confirmation!

closed #4

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.