[wp-hackers] WP and Plugins DB connection conflicts

Peter Adams peter at oncefuture.com
Tue Jun 26 21:17:00 GMT 2007


sorry, let me be more clear.

There are cases when plugins need to create/manage/teardown their own  
link to the same database that WP uses using the exact same user  
credentials.  This is very handy when you need a dedicated or  
persistent db link or need to produce and ignore errors on that link.  
PHP's mysql_connect will attempt to reuse an existing connection with  
the same credentials unless you set the new_link bool.

What I was suggesting was to force php to create a new link to the DB  
when $wpdb is _first_ created - not every time it's accessed. The  
benefit here is that Wordpress is then guaranteed to have it's own db  
connection instead of potentially piggy-backing on one that is  
already created by a plugin that is using the same db credentials.

-P-

On Jun 26, 2007, at 7:01 AM, Otto wrote:

> If you want to access a different database entirely, you shouldn't use
> the $wpdb functions at all, IMO. Do your own mysql_connect and such,
> and you won't have any conflicts. And if you do want to access the
> wordpress database, use $wpdb. Seems simple enough.
>
> I think a lot of this problem is plugin-author-error as opposed to an
> issue with Wordpress.
>
> More to the point, it seems like an extremely bad idea to modify the
> $wpdb to be forced to open a new link every time. It would add a lot
> of overhead that might not always be absolutely necessary.
>
>
> On 6/26/07, Jennifer Hodgdon <yahgrp at poplarware.com> wrote:
>> >> I believe the usual thing for a plugin is to use $wpdb to do  
>> database
>> >> queries, rather than creating its own database connections. Is  
>> there
>> >> some reason these plugins cannot be rewritten to do that? It might
>> >> mean adding a require() line somewhere, to make sure $wpdb has  
>> been
>> >> initialized, but then there would be no conflict.
>>
>> > I think the issue arrises when a Plugin wants to access a seperate
>> > database than Wordpress's.
>> > I saw a Trac ticket which refered to something similar earlier  
>> actually:
>> > http://trac.wordpress.org/ticket/2722
>> > the solution in the Ticket description isnt the best though.
>>
>> In this case, the person who posted to the list said he was  
>> logging in
>> with the same credentials as WP, though. Most plugins (I think) use
>> the WP db, since some users on shared hosts will not have permission
>> to create new DBs, and anyway people probably want all their
>> WP-related data in the same database.  The Trac post was in  
>> regards to
>> using a db on a completely different host.
>>
>>       -- Jennifer
>> _______________________________________________
>> wp-hackers mailing list
>> wp-hackers at lists.automattic.com
>> http://lists.automattic.com/mailman/listinfo/wp-hackers
>>
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers



More information about the wp-hackers mailing list