Provide mechanism for PDO to throw away a persistent connection and get a new one#21007
Draft
NattyNarwhal wants to merge 1 commit intophp:masterfrom
Draft
Provide mechanism for PDO to throw away a persistent connection and get a new one#21007NattyNarwhal wants to merge 1 commit intophp:masterfrom
NattyNarwhal wants to merge 1 commit intophp:masterfrom
Conversation
The persistent connection may be in a wedged or otherwise undesirable state that the connection liveness check has failed to deal with. If so, provide userland code a way to get rid of a persistent connection and create a new one in its place. I'm not entirely pleased with this approach, but perhaps there is a better one.
Member
Author
|
Example: <?php
$dsn = "";
$username = "";
$password = "";
$attrs = [PDO::ATTR_PERSISTENT => true];
if (isset($_GET["new"])) {
$attrs[PDO::ATTR_PERSISTENT_NEW_CONNECTION] = true;
}
$odbc = new PDO($dsn, $username, $password, $attrs);
// example database specific method to see if we're connected to the same database process
$stmt = $odbc->prepare("select JOB_NAME from table(QSYS2.ACTIVE_JOB_INFO(JOB_NAME_FILTER => '*'))");
$stmt->execute();
$rows = $stmt->fetchAll();
echo "<pre>";
var_dump($rows);
echo "</pre>";
?>
<form action="/new.php">
<input type="checkbox" name="new" id="new" />
<label for="new">New job</label>
<input type="submit" />
</form> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The persistent connection may be in a wedged or otherwise undesirable state that the connection liveness check has failed to deal with. (For instance, the ODBC connection dead attribute that PDO_ODBC uses to check isn't perfectly handled by all drivers, or if a persistent connection has bad persistent state, it's easier to just reconnect if so.) If so, provide userland code a way to get rid of a persistent connection and create a new one in its place.
This is prompted by the discussion in GH-15749 and GH-19933. I think adding a notion of disconnected PDO objects is probably unwise, so this provides an alternative that requires very minimal changes in PDO. I'm not entirely pleased with this approach, but perhaps there is a better one. I don't intend to get this merged, without a discussion anyways - I'll bring that up on internals.