Transactions and Exclusions

I thought I would ask because I'm not sure that the result of this operation did not work with transactions very rudely.

When an exception is thrown in PHP, how is the database transaction handled. Does it automatically roll back from the moment the connection to the database is removed from PHP or are the locks in place?

Pseudo code

TX Begin
Select Balance
Logic in PHP
  Exception 
  Rollback
Commit

Note: I know that best coding practice dictates that I roll back to catch. This is just the behavioral question I asked about.

+4
source share
1 answer

To determine how MySQL processes transactions when a connection (session) is completed, we need to consider whether the mode is enabled autocommitor not.

  • autocommit , autocommit :

    START TRANSACTION , COMMIT ROLLBACK. .

    1. , . , , (, ). , .

, @MarkBaker, , , . , , , PHP , .

+1

Source: https://habr.com/ru/post/1672730/


All Articles