Skip to content

Commit bdf7699

Browse files
committed
Added possibility to configure isolation level for mysql connections
1 parent 75792f4 commit bdf7699

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/Illuminate/Database/Connectors/MySqlConnector.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ public function connect(array $config)
2727
$connection->exec("use `{$config['database']}`;");
2828
}
2929

30+
$this->configureIsolationLevel($connection, $config);
31+
3032
$this->configureEncoding($connection, $config);
3133

3234
// Next, we will check to see if a timezone has been specified in this config
@@ -44,7 +46,25 @@ public function connect(array $config)
4446
*
4547
* @param \PDO $connection
4648
* @param array $config
47-
* @return void
49+
* @return void|\PDO
50+
*/
51+
protected function configureIsolationLevel($connection, array $config)
52+
{
53+
if (! isset($config['isolation_level'])) {
54+
return $connection;
55+
}
56+
57+
$connection->prepare(
58+
"SET SESSION TRANSACTION ISOLATION LEVEL '{$config['isolation_level']}'"
59+
)->execute();
60+
}
61+
62+
/**
63+
* Set the connection character set and collation.
64+
*
65+
* @param \PDO $connection
66+
* @param array $config
67+
* @return void|\PDO
4868
*/
4969
protected function configureEncoding($connection, array $config)
5070
{

0 commit comments

Comments
 (0)