WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] Access non-WP tables in db

[Resolved] Access non-WP tables in db

  • 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

Viewing 5 replies - 1 through 5 (of 5 total)
  • 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.

    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

    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

    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

    I decided to use Meta Boxes instead – easier to just use WordPress for this extra info 🙂

    Thanx,
    Daniel

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘[Resolved] Access non-WP tables in db’ is closed to new replies.