Opened 21 years ago
Closed 20 years ago
#2233 closed enhancement (invalid)
wpdb constructor should create a new connection
| Reported by: | thomasq | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | Administration | Version: | 2.0 |
| Severity: | normal | Keywords: | |
| Cc: | Focuses: |
Description
The constructor for MySQL connections should create a new transport connection each time
it is called. Otherwise, an import plugin that wants to connect on a database that resides
on the same server as the Wordpress database may incorrectly mess up the Wordpress $wpdb.
Attachments (2)
Change History (11)
#2
@
21 years ago
I do not foresee any breakage; on my setup, Wordpress seems to be happy with the change.
#3
@
21 years ago
A better solution would be using $this->dbh as part of all the mysql calls in the wpdb class instead, so that anyone else who uses mysql calls can use their constructor, as you should, for their own code. This would also allow multiple instances of the wpdb class.
#4
@
21 years ago
I would agree with masquerade on that one. If we want to allow for multiple connections on the database, it makes more sense to include the link identifiers in all calls to the database. This allows for multiple unique instances of the database connection to be available if necessary. I've added a patch that does this. There are only two instances where it matters.
#5
@
21 years ago
masquerade, abhay,
The original patch from thomasq is correct. wpdb constructor must force a new database connection, otherwise imports from different databases on the same host with the same username and password as the main WP database will fail.
The problem is not where $this->dbh is used. The problem is that $this->dbh on two supposedly independent wpdb objects are references to the same underlying database connection object, making wpdb::select() change the active database for all of them, including the global $wpdb, which side-effect causes the failure.
Would this break anything? I can't see WordPress creating another instance of $wpdb, so it should be harmless.