-
Notifications
You must be signed in to change notification settings - Fork 889
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix setting persistent option for PDO connection #2092
Fix setting persistent option for PDO connection #2092
Conversation
…n' into feature/pdo-persistent-connection
Co-authored-by: Matthew Peveler <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does attr_persistent
work for SQL Server? If not, would there be any harm in passing it as an option anyway?
If either of the above is "yes", I think it would make sense to lift the code setting this option out of the specific adapters into the PdoAdapter::createPdoConnection
method, having it be:
$adapterOptions = $this->getOptions() + [
'attr_errmode' => PDO::ERRMODE_EXCEPTION,
];
if (isset($adapterOptions['attr_persistent'])) {
$driverOptions[PDO::ATTR_PERSISTENT] = $adapterOptions['attr_persistent'];
}
This way we are following DRY principles.
No, SQL Server does not support persistent connections. And that's why I have moved the setting of driver attribute out from PDOAdapter to specific MySQL, Postgres and SQLite. For SQL Server nothing changes in comparison to current behavior.
Yes, that was my first solution (7a49fa2), but I have found that it could break SQL server functionality and moved it out in 2b86062. |
Alright, I found microsoft/msphpsql#65 which confirms that setting that will in fact cause the driver to throw an exception, so we cannot set it for all drivers. I'm fine with just ignoring it for mssql as opposed to throwing an exception like |
I think we need to merge this master branch into 0.x and then stop using master (as default). |
We have a small discussions on this in the phinx-dev channel. Leaving it up to @markstory still, but @MasterOdin had some thoughts after I explained the naming alignment. |
I've opened #2097 to discuss the branch switch and can carry this conversation there. |
This fixes the ability to use persistent connections by PDO.
One can set generic PDO attributes (#1904) but the attribute - \PDO::ATTR_PERSISTENT - is useless while setting it by setAttribute after PDO object instantiation:
From the point of view of usage, nothing changes: like other PDO arguments we specify
attr_persistent => true
config option. Before the PDO instatiation this attribute (if specified) is passed to driver options instead of setting in setAttribute after it.It's done in Mysql, Postgres and SQLite adapters. SQL Server PDO driver does not support this specific attribute.