You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is a feature request or an edge-case bug report.
MySqliDriver closes the connection upon destruction of its parent Connection object: Connection::__destruct ⟶ Connection::disconnect ⟶ MySqliDriver::disconnect (code here) ⟶ \mysqli::close
In a scenario like the following this behaviour will cause an error.
$container['database'] = new \mysqli($cfg['host'], $cfg['username'], $cfg['password'], $cfg['database']);
functiondoSomething(\mysqli$connection) {
$dibi = newConnection(config: [
'resource' => $connection,
'driver' => 'mysqli',
]);
$dibi->query(...);
return;
// at this point the $dibi variable goes out of scope and is destructed
}
/** @var \mysqli $db */$db = $container->get('database');
// side-effect here, the DB disconnects after this function returnsdoSomething($db);
// and then... oops!$db->query(...); // Error: mysqli object is already closed
Even though this is an edge case, the scenario should be supported. PdoDriver::disconnect() does not do this, it simply nulls the connection; I haven ot checked the other drivers.
This is a feature request or an edge-case bug report.
MySqliDriver
closes the connection upon destruction of its parentConnection
object:Connection::__destruct
⟶Connection::disconnect
⟶MySqliDriver::disconnect
(code here) ⟶\mysqli::close
In a scenario like the following this behaviour will cause an error.
Even though this is an edge case, the scenario should be supported.
PdoDriver::disconnect()
does not do this, it simply nulls the connection; I haven ot checked the other drivers.Suggested solution
I suggest something like this:
... and adding
$this->initializedWithResource = true
in the constructor here.I am able to provide a PR.
The text was updated successfully, but these errors were encountered: