Skip to content

Conversation

rposky
Copy link

@rposky rposky commented Sep 23, 2025

An RFC accompanying this PR will soon be created, and I will update this description with a link once it is so.

This PR was initially opened as #19214, but which targeted PHP 8.3, and so is re-created here now targeting PHP 8.6.

…object.

Added disconnect for __destruct alternative to disconnect from db, related to
bug #40681 and requests #62065 and #67473. Added PHP::isConnected to yield
current connection status.

PDO to produce SQLSTATE error 01002 "Disconnect error" and in accordance with
error execution mode when database interaction prompted on disconnected PDO.

Fixed bug #63343 in rework of PDO pdo_dbh_free_storage logic to avoid
transaction rollback against persistent db connection. Integrated regular
resource with persistent connection for end-of-request hook to invoke
persistent shutdown and rollback.

Added pdo_is_persisted and pdo_list_entry_from_key helpers to determine when
persistent db handler is actively registered as resource, avoiding opaque use of
_pdo_dbh_t::refcount to this end.

Updated php_pdo_internal_construct_driver to consume added list entry helper
and to check _pdo_dbh_t::is_closed in addition to liveness when validating a
discovered persistent db connection for re-use. Removed extraneous call to
zend_list_close given that only a persistent destructor is defined for the
_pdo_dbh_t resource that zend_list_close does not invoke.

Fixed potential for bad memory access in persistent connections from former PDO
objects, once the connection has been replaced due to liveness check failure.
The resource was freed without invalidating other PDO object references, but
now the resource will not be freed until the last referring PDO object is
freed.

Made _pdo_dbh_t::refcount accurate and consistent, regardless of persistent
connection, to represent count of PDO object's referencing the handle. In the
case of persistent connections, the count was +1, and in the case of
non-persistent connections, never decremented.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant