Forums

multiple wpdb instances don't work. (5 posts)

  1. pyeager
    Member
    Posted 2 years ago #

    Scenario:

    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.

  2. pyeager
    Member
    Posted 2 years ago #

    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)

  3. pyeager
    Member
    Posted 2 years ago #

    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?

  4. dnxpert
    Member
    Posted 2 years ago #

    Anyone ever figure this out?

    I am having the same problem.

  5. dnxpert
    Member
    Posted 2 years ago #

    Here is a solution if anyone is looking for it:
    http://wordpress.org/support/topic/388990?replies=4#post-1481489

Topic Closed

This topic has been closed to new replies.

About this Topic