Forum Replies Created

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter pyeager

    (@pyeager)

    Hmmmm…. here is how the wpdb object connects to the database:

    $this->dbh = @mysql_connect($dbhost, $dbuser, $dbpassword, true);

    As Zaine pointed out in one of the above-referenced threads, this should work properly, unless sql.safe_mode is turned on in php.ini. However, sql.safe_mode is turned off on my system, and it behaves as if it was turned on.

    Could this be a bug in PHP?

    Thread Starter pyeager

    (@pyeager)

    Below are some other threads on this issue. While they are marked “resolved”, they appear to refer to this same issue.

    [resolved] Connecting to another mysql database (12 posts)

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

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

    https://www.ads-software.com/support/topic/355262?replies=1#post-1362072

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

    https://www.ads-software.com/support/topic/355262?replies=1#post-1362072

    I have stumbled upon the same issue upon which Zaine has commented, but I’m having it in a different context. Here is a short description.

    1. Plugin A creates a new wpdb object to access a second database, using the following line within a PHP function:
    $lwpdb = new wpdb( $user, $pass, $db, $host );

    2. Plugin B attempts to reference the wordpress database via the wpdb object created by wordpress, using these lines within a function:
    global $wpdb;
    $sql = "select * from $mi_table_name";
    $results = $wpdb->get_results( $sql, ARRAY_A );

    3. Then the fun begins. Plugin B’s query gets run against the database referenced by Plugin A. I know that this is happening by the error message, which clearly states that the query is failing due to lack of select privileges on Plugin A’s database.

    This has to be either a bug or a failure to properly document the behavior of the wpdb object.

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

Viewing 6 replies - 1 through 6 (of 6 total)