Skip to content

Commit 202e521

Browse files
[11.x] MySQL transaction isolation level fix (#50689)
* Fix transaction isolation level in MySqlConnector.php * Update DatabaseConnectorTest.php * Style fix * Code style fix --------- Co-authored-by: Graham Campbell <[email protected]>
1 parent bd096bc commit 202e521

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/Illuminate/Database/Connectors/MySqlConnector.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,12 @@ protected function getHostDsn(array $config)
9393
*/
9494
protected function configureConnection(PDO $connection, array $config)
9595
{
96-
$statements = [];
97-
9896
if (isset($config['isolation_level'])) {
99-
$statements[] = sprintf('SESSION TRANSACTION ISOLATION LEVEL %s', $config['isolation_level']);
97+
$connection->exec(sprintf('SET SESSION TRANSACTION ISOLATION LEVEL %s;', $config['isolation_level']));
10098
}
10199

100+
$statements = [];
101+
102102
if (isset($config['charset'])) {
103103
if (isset($config['collation'])) {
104104
$statements[] = sprintf("NAMES '%s' COLLATE '%s'", $config['charset'], $config['collation']);

tests/Database/DatabaseConnectorTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ public function testMySqlConnectCallsCreateConnectionWithIsolationLevel()
6262
$connector->expects($this->once())->method('getOptions')->with($this->equalTo($config))->willReturn(['options']);
6363
$connector->expects($this->once())->method('createConnection')->with($this->equalTo($dsn), $this->equalTo($config), $this->equalTo(['options']))->willReturn($connection);
6464
$connection->shouldReceive('exec')->once()->with('use `bar`;')->andReturn(true);
65-
$connection->shouldReceive('exec')->once()->with("SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ, NAMES 'utf8' COLLATE 'utf8_unicode_ci';")->andReturn(true);
65+
$connection->shouldReceive('exec')->once()->with('SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ;')->andReturn(true);
66+
$connection->shouldReceive('exec')->once()->with("SET NAMES 'utf8' COLLATE 'utf8_unicode_ci';")->andReturn(true);
6667
$result = $connector->connect($config);
6768

6869
$this->assertSame($result, $connection);

0 commit comments

Comments
 (0)