• I have a function and am rewriting it to be portable. My functions is calling 2 db tables, 1st it calls the db table in my DB.userdb then is to call the wordpress wp_users table.

    In my function I gave global $config, $wpdb;
    then I select * from my $config[table_prefix]usersdb
    I then want to loop through the results to match values in my wordpress wp_users table.

    I have to use DB_name.wp_users in my second select to get it to work. I cannot get $wpdb->prefix.”users” to work it is only outputting the wp_users and it needs to include the DBname also.

    Can anyone tell me what I am missing?
    Trying to do a quert from two different DBs without having to hard code either of the 2 db names in the select statements

Viewing 2 replies - 1 through 2 (of 2 total)
  • You’re missing the fact that WordPress is not intended to work with multiple databases. The simplest way to resolve your problem is to move your tables into WordPress’ database. Also, you are using a needlessly convoluted approach to data lookups. Instead of first running a query on one table and then use its results to issue a bunch of other queries to run on another table, you should consider issuing one query on both tables joined together (which, again, is very easy to do when both tables in question belong to the same database).

    Thread Starter alsmith

    (@alsmith)

    I figured out a way to accomplish this so I thought I would post it.
    Before I call the 2nd DB I did this.
    global $wpdb;
    $db=DB_NAME;
    $usertable = “db.”/$wpdb->prefix.”users”;

    Now I have $usertable from WordPress I can use throughout my plugin and works fine.
    This proves to be a much easier method than combining the tables into one DB. Well, for me anyway.
    Since this is not new installations it would take much more work to combine the 2 stand alone applications.
    If both apps were using the same database it would be a no brainer but since they were not it was.
    Oh well, maybe someone else will find this useful.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘include 2 diff dbs in plugin function’ is closed to new replies.