[wp-hackers] WP and Plugins DB connection conflicts

Peter Adams peter at oncefuture.com
Wed Jun 27 04:37:54 GMT 2007


you are right. after testing this out the issue is that prior to v2.1  
wp-db.php was calling the mysql_error() method without specifying the  
link resource. that would print errors on all links. It looks like  
this was fixed in v2.1 but it's still out there in the wild for  
people running v2.0.

$wpdb->hide_errors() is your friend.

-P-

On Jun 26, 2007, at 2:37 PM, Peter Westwood wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Peter Adams wrote:
>> 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.
>>
>
> If you want to produce and ignore errors then call $wpdb->hide_errors
> and $wpdb->show_errors around your queries.
>
>> 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.
>>
>
> wp-db.php is included way before plugins and so it would be the other
> way round -> the plugin would be piggybacking on the normal wpdb link.
>
> I don't see how making this change to $wpdb to mean that it always
> creates a new connection is benificial to most users of WordPress.
>
> If you have a specific situation where you need this functionality  
> then
> override wpdb with your own db class using the functionality provided.
>
> westi
> - --
> Peter Westwood
> http://blog.ftwr.co.uk
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.2 (MingW32)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>
> iD8DBQFGgYb9VPRdzag0AcURAi6nAJ4p8cn/ZuAJHDJQ/e9mvNn8edQYWQCeO4TC
> lF/j7psBh25bTEg81leZoW0=
> =enWI
> -----END PGP SIGNATURE-----
> _______________________________________________
> 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