Support » Fixing WordPress » re-connect to WP database after query to other database

  • Resolved rotezecke


    Hi there,
    i have a WP site where one page has to access another database.
    it all works well but the navigation on the bottom goes missing.

    both top and bottom navigation are created using:

    after some fiddling i determined that WP looks for the function in the wrong database.

    Table ‘xxxx.wp_posts’ doesn’t exist

    where xxxx is the database i just queried. how do i get back to the WP database?


Viewing 3 replies - 1 through 3 (of 3 total)
  • rotezecke


    ok, just did
    mysql_select_db($DATABASE_WP,$CONNECT) or die(“database not found”);
    where $DATABASE_WP is my WP database.
    too easy.



    Hi, can you please clarify that? What would i use for $CONNECT, to reconnect to my WordPress? I just tried “$wpdb” but that wasn’t right.



    Hi there

    $CONNECT=mysql_connect($SQLHOST,$SQLUSER,$SQLPW) or die("could not connect");
    mysql_select_db($DATABASE,$CONNECT) or die("database not found");

    all the variables are defined in your wp-config.php (different variable names though).

    $SQLHOST is probably localhost, $SQLUSER is the wordpress username,
    $SQLPW the password and $DATABASE the wordpress database.

    now i have no idea whether this is good practice, or secure. i am not familiar with wordpress specific code, like “$wpdb”.

    hope this helps

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘re-connect to WP database after query to other database’ is closed to new replies.