WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Access non-WP tables in db (6 posts)

  1. danpkraus
    Member
    Posted 3 years ago #

    I have extra information for each one of my custom post types stored in another DB. The queries I am making to that DB are breaking plugins so I thought I would import that DB's tables into the WP DB.

    Apparently I cannot access those tables with $wpdb. I've followed the instructions on the $wpdb class codex page and several other posts I've found but with no luck. I would like to not have to use custom fields for all of this extra info so the DB seems the best option.

    Here is my function:
    [Code moderated as per the Forum Rules. Please use the pastebin]

    Any help is greatly appreciated :)

    Thanx,
    Daniel

  2. vtxyzzy
    Member
    Posted 3 years ago #

    You should be able to access any table in the database that contains the WordPress tables using $wpdb->get_results(). Just name the table(s) in a SELECT query.

  3. danpkraus
    Member
    Posted 3 years ago #

    these are non-wordpress tables. As in not installed by WordPress. I figured I couldn't access tables not installed by wordpress so i tried something different...

    I tried creating a new instance of $wpdb and using that to access a second database instead but it only worked sometimes, and now not at all. It's just strange that no matter what I do I can't seem to get at this other data.

    I may just have to input all of it as met boxes or custom fields to get it to display for each post.

    Any help or directon would be great.

    Thanx,
    Daniel

  4. danpkraus
    Member
    Posted 3 years ago #

    I noticed I had placed a "mysql close" at the end of several functions - I removed them and now everything seems to be working fine.

    Thanx

  5. danpkraus
    Member
    Posted 3 years ago #

    So I uploaded the new queries and they do not work using $wpdb->get_results.

    I added tables to the WP database and it worked here at home on my localhost but not live. Why would that be?

    Here is my code:
    $row = $wpdb->get_results("SELECT my_rows_here FROM $wpdb->my_table WHERE co_name = '".$variable."'", ARRAY_A);

    but I always get an empty set - almost as if the query is not being made. Could it be my $variable? I've tried no quotes, quotes double quotes and everything else to get the $variable to take but nothing works. Any ideas?

    Thanx,
    Daniel

  6. danpkraus
    Member
    Posted 3 years ago #

    I decided to use Meta Boxes instead - easier to just use WordPress for this extra info :)

    Thanx,
    Daniel

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags