Ticket #2722 (closed enhancement: fixed)

Opened 2 years ago

Last modified 5 months ago

Using multiple wpdb instances

Reported by: Philnate Assigned to: Nazgul
Priority: normal Milestone: 2.5
Component: General Version: 2.0.2
Severity: normal Keywords: wpdb class has-patch
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

2722.diff (1.5 kB) - added by Nazgul on 01/31/08 20:51:45.

Change History

05/22/06 10:28:32 changed by philnate

  • milestone set to 2.0.3.

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.

05/22/06 11:33:14 changed by masquerade

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.

05/27/06 17:10:45 changed by philnate

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?

09/21/06 01:09:38 changed by foolswisdom

  • milestone changed from 2.0.3 to 2.2.

03/27/07 22:06:20 changed by foolswisdom

  • milestone changed from 2.2 to 2.4.

10/03/07 16:01:23 changed by Nazgul

  • owner changed from anonymous to Nazgul.
  • status changed from new to assigned.

01/31/08 20:51:45 changed by Nazgul

  • attachment 2722.diff added.

01/31/08 20:53:22 changed by Nazgul

  • keywords changed from wpdb class to wpdb class has-patch.
  • type changed from defect to enhancement.
  • summary changed from long winded way to use two wpdb instances to Using multiple wpdb instances.

01/31/08 22:09:18 changed by ryan

  • status changed from assigned to closed.
  • resolution set to fixed.

(In [6701]) Allow multiple db instances. Props Nazgul. fixes #2722