Support » Plugins » $WPDB using incorrect DB connections

  • Resolved Zaine


    I’ve just run into:

    which is marked as resolved, but I don’t believe it is. As my post says on the bottom of the above post, it appears that WPDB will blindly use the last MySQL connection, rather than use the one it should?

    This isn’t a situation I can replicate on my own box for an example, but I’ve had someone attempting to use one of my plugins just run into it.

Viewing 4 replies - 1 through 4 (of 4 total)
  • I believe I have ran into this exact issue. Your plugin appears to be unable to access its own table in the wpdb to grab a verb to use. Not being any good at php, I decided just to replace the error with defining a single verb to use which allows the plugin to finally work.

    Unfortunately the problem is much more than I thought. If I place this widget above another one, like the RSS Widget, the entire site will go blank on me. Only if this widget is placed under the RSS Widget will the site continue to function. If I place other widgets like a custom one that only displays an image, or the regular Meta widget below this one, all is fine. Now I assume this is because the RSS Widget accesses wpdb.

    I don’t know crap about php, but I do know a serious problem when I see one. The only work-around I can think of is simply merging the killboard and wordpress databases.

    Worked this out thanks to

    Basically this issue is that I was using:

    $killdb_link = @mysql_connect($adminOptions[‘eveDatabaseServer’], $adminOptions[‘eveDatabaseUsername’], $adminOptions[‘eveDatabaseSecret’]);

    expecting php to create a new connected. Well, it doesn’t. You need the following:

    $killdb_link = @mysql_connect($adminOptions[‘eveDatabaseServer’], $adminOptions[‘eveDatabaseUsername’], $adminOptions[‘eveDatabaseSecret’], TRUE);

    The TRUE on the end forces a new connection. This prevents us missing WordPress’s connection to the DB.

    More info on: but worth noting the following:

    “In SQL safe mode, this parameter is ignored. ”

    Thanks, Zaine!

    I was having the exact same problem with a plugin that needs to access a database separate from the main wordpress db.

    While the information you provide will help me get the project moving again, it seems that this may indicate a flaw in the wpdb class.

    Because I thought it would make for a cleaner implementation, I access the wp database via the wpdb class. Everything was peachy until I started working on this plugin that needed to access an additional database.

    WordPress instantiates a wpdb object for database access. My plugins use that one to access the wordpress database. My plugin instantiates another wpdb object to access another database. This *should* work fine, according to the wp docs I have read.

    The problem is that, as you described in your original post, once you access the second database, *both* wpdb objects seem to reference that database!

    I’m kinda new here, so I guess I’ll check the references in this thread, and see if there is a bug report that needs to be filed or commented on.

    Thanks again, Zaine, for posting this topic! It’s nice to know I’m not crazy after all (at least when it comes to wp databases!)

    New post on this topic at the link below, since there appears to be an actual bug.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘$WPDB using incorrect DB connections’ is closed to new replies.