2
votes

I have been reading about setting the isolation levels of transactions. But couldn't really find a straight answer to the simple question:

Do I first set the isolation level and then start the transaction or vice versa.

START TRANSACTION
SET TRANSACTION ISOLATION LEVEL READ COMMITTED

So which command comes first? Does it even matter?

PS: Is there any disadvantage about using transactions/isolation levels for PHP/MySQL sites?

1
PS: I read that transactions might not even work when you have the MyISAM engine? - Gilles Lesire

1 Answers

2
votes

You should set the transaction level first:

SET TRANSACTION ISOLATION LEVEL READ COMMITTED;
START TRANSACTION;

as you can't change the isolation level from within a transaction.

In fact, attempting to is the only way to tell if you're inside a transaction with certain versions of MySQL.