Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mySQL - Set isolation level using PHP's mysqli

How do I set the isolation level of a transaction to 'SERIALIZABLE' in PHP using mysqli? I have looked everywhere and I can't find any information on it.

Here is an explanation of the isolation levels.

like image 986
Mark Avatar asked Feb 28 '23 01:02

Mark


1 Answers

You can just set the isolation level in a query before you run your statements. This assume that you do everything using the same session:

$mysqli = new mysqli('localhost', 'user', 'pass', 'db');
$mysqli->query("SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE");
...

You may also want to turn off autocommit before hand since it changes the way serializable isolation works.

like image 188
carson Avatar answered Mar 05 '23 17:03

carson