-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
No explicit USE database
statement
#54132
Conversation
No need to explicitly send another `USE database` statement. The database is already selected via the DSN string. Multiple reasons for this: - One less round trip per connection - No connection pinning when used with a proxy (e.g. RDS Proxy).
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.
This cannot be removed. It's necessary when persistent connections are enabled. It's also necessary for other MySQL compatible databases.
Can you elaborate why this is needed for persistent connections? Also, which other mysql databases? If they are mysql compatible, then I would assume they also allow the database to be specified in the DSN. We currently have the problem that we first of all need to get rid of any unnecessary round trip to the DB and also avoid connection pinning via RDS proxy. This non configurable behaviour forces us to overwrite this class or use a custom driver in all services. It would be nice if this can be solved directly on the framework. Same as all the other optional SET operations (timezone, mode, charset etc.) Based on docs I have found, if the database is specified in the DSN, PDO takes care of ensuring that the right DB is selected (even for persistent connection). So it is not necessary to send out another USE statement on application level. We have been using persistent connections for quite some time (with cakephp, there no explicit USE call is done), and we never had to send an explicit USE statement. (We use AWS Aurora MySQL + MySQL locally). Proposal: To be 100% backwards compatible just in case (if you don't trust it to be like I described), allow setting a new config value to skip setting the database explicitly. Edit:
|
I'd rather see this in 12.x as a breaking change. |
In my experience, this is pretty unreliable, and this may cause subtle bugs for people. |
oh, nvm. i see config got added, and it defaults to the same behiavour. :P |
Thanks guys! This saves us some work. |
@TheLevti maybe add a config option to the docs/config files describing this option? |
Will do that. |
No need to explicitly send a
USE database
statement. The database is already selected via the DSN string.Multiple reasons for this: