Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 522
Nikolay 'Alagunto' Tkachenko Avatar asked Dec 04 '17 22:12

Nikolay 'Alagunto' Tkachenko


People also ask

Which is the default transaction isolation level?

Transaction Isolation Levels The default isolation level is REPEATABLE READ . Other permitted values are READ COMMITTED , READ UNCOMMITTED , and SERIALIZABLE .

What are the four transaction isolation levels?

four transaction isolation levels in SQL Server 7.0: Uncommitted Read (also called "dirty read"), Committed Read, Repeatable Read, and Serializable.

How do I change the isolation level in mysql?

To set the global isolation level at server startup, use the --transaction-isolation= level option on the command line or in an option file. Values of level for this option use dashes rather than spaces, so the permissible values are READ-UNCOMMITTED , READ-COMMITTED , REPEATABLE-READ , or SERIALIZABLE .

What is transactional isolation?

What Does Transaction Isolation Level Mean? The transaction isolation level is a state within databases that specifies the amount of data that is visible to a statement in a transaction, specifically when the same data source is accessed by multiple transactions simultaneously.


1 Answers

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');
like image 181
Lewis Johnson Avatar answered Nov 04 '22 04:11

Lewis Johnson