Opened 19 years ago
Closed 17 years ago
#2722 closed enhancement (fixed)
Using multiple wpdb instances
Reported by: | Philnate | Owned by: | Nazgul |
---|---|---|---|
Milestone: | 2.5 | Priority: | normal |
Severity: | normal | Version: | 2.0.2 |
Component: | General | Keywords: | wpdb class has-patch |
Focuses: | Cc: |
Description
For my plugin I need to allow the user to use different databases, hosts, users and passwords therefor I created my own wpdb class instance:
$phpbbdb= new wpdb($pBBuser, $pBBpassword, $pBBdb, $pBBhost);
But if now something after this line access the database through the wpdb instance is using the phpbbdb resource id and therefor the Query isn't successful as the database don't hold these wordpress tables.
To remove this problem I need to use this line at the end of my code:
$phpbbdb= new wpdb(DB_USER,DB_PASSWORD,DB_NAME,DB_HOST);
As I found out, this problem can easily be resolved by changing this line, within the wp-db.php file:
$this->dbh = @mysql_connect($dbhost, $dbuser, $dbpassword);
into this one:
$this->dbh = @mysql_pconnect($dbhost, $dbuser, $dbpassword);
I'm not sure if this change would create other problems as I'm not too deep into PHP+MySQL, but while working with the persistance connection, I didn't encounter some Problems.
Thanks
Attachments (1)
Change History (9)
#2
@
19 years ago
You're barking up the wrong tree. What you should be looking at is passing $this->dbh to every query, and changing mysql_connect's fourth parameter (bool new_link) to true, so that you get a new connection for each instance of the class. Persistant connections often have serious adverse side-effects, and your milage will vary based on server specifications, configuration, and traffic. We unfortunately do not have the luxury of assuming everyone has a server configured properly enough to not die under the load that persistant connections potentially creates when it comes under high traffic.
#3
@
19 years ago
But to use this parameter would cause that Wordpress needs atleast MySQL 4.2 .
Am I right if this change will mostly not be added as this would set the requirements too high?
So I need to provide the "fix" within the widgets?
Maybe atleast the option for a persistence connection should be added, as a new optional parameter. Which uses in default a non persistence connection. So no changes would be needed in templates and other components.