Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion system/Database/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ public static function connect($group = null, bool $getShared = true)

$connection = static::$factory->load($config, $group);

static::$instances[$group] = $connection;
if ($getShared) {
static::$instances[$group] = $connection;
}

return $connection;
}
Expand Down
18 changes: 18 additions & 0 deletions tests/system/Database/Live/ConnectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,22 @@ public function testConnectWithFailover(): void

$this->assertGreaterThanOrEqual(0, count($db1->listTables()));
}

public function testNonSharedInstanceDoesNotAffectSharedInstances(): void
{
$firstSharedDb = Database::connect('tests');
$originalDebugValue = (bool) self::getPrivateProperty($firstSharedDb, 'DBDebug');

$nonSharedDb = Database::connect('tests', false);
self::setPrivateProperty($nonSharedDb, 'DBDebug', ! $originalDebugValue);

$secondSharedDb = Database::connect('tests');

$this->assertSame($firstSharedDb, $secondSharedDb);
$this->assertNotSame($firstSharedDb, $nonSharedDb);

$this->assertSame($originalDebugValue, self::getPrivateProperty($firstSharedDb, 'DBDebug'));
$this->assertSame($originalDebugValue, self::getPrivateProperty($secondSharedDb, 'DBDebug'));
$this->assertSame(! $originalDebugValue, self::getPrivateProperty($nonSharedDb, 'DBDebug'));
}
}
2 changes: 2 additions & 0 deletions user_guide_src/source/changelogs/v4.6.4.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ Deprecations
Bugs Fixed
**********

- **Database:** Fixed a bug in ``Database::connect()`` which was causing to store non-shared connection instances in shared cache.

See the repo's
`CHANGELOG.md <https://github.com/codeigniter4/CodeIgniter4/blob/develop/CHANGELOG.md>`_
for a complete list of bugs fixed.
Loading