WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] re-connect to WP database after query to other database (4 posts)

  1. rotezecke
    Member
    Posted 3 years ago #

    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:
    wp_page_menu('include=x,y,z');

    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?

    cheers

  2. rotezecke
    Member
    Posted 3 years ago #

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

  3. tzeldin88
    Member
    Posted 3 years ago #

    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.

  4. rotezecke
    Member
    Posted 3 years ago #

    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

Topic Closed

This topic has been closed to new replies.

About this Topic