phplaraveltransactionsisolation-level

How do I set transaction isolation level in Laravel 5.5?


In laravel 5.5 with MySQL I use \Illuminate\Support\Facades\DB to create transactions this way:

DB::transaction(function() {
    ...
});

What is the isolation level for such transaction and is there a way to set it explicitly?


Solution

  • The default in SqlLite is

    'BEGIN IMMEDIATE TRANSACTION';
    

    The default in MySQL is

    'SET TRANSACTION ISOLATION LEVEL READ COMMITTED';
    

    You can set it yourself by doing something like this

    $pdo = DB::connection()->getPdo();
    $pdo->exec('SET TRANSACTION ISOLATION LEVEL READ COMMITTED');