WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] $WPDB using incorrect DB connections (5 posts)

  1. Zaine
    Member
    Posted 5 years ago #

    I've just run into:
    http://wordpress.org/support/topic/275658?replies=9#post-1161558

    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.

  2. randaijala
    Member
    Posted 4 years ago #

    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.

  3. Zaine
    Member
    Posted 4 years ago #

    Worked this out thanks to http://wordpress.org/extend/plugins/profile/leewillis77

    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: http://uk2.php.net/manual/en/function.mysql-connect.php but worth noting the following:

    "In SQL safe mode, this parameter is ignored. "

  4. pyeager
    Member
    Posted 4 years ago #

    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!)

  5. pyeager
    Member
    Posted 4 years ago #

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

    http://wordpress.org/support/topic/355262?replies=1#post-1362072

Topic Closed

This topic has been closed to new replies.

About this Topic