• Hi there,
    I am currently developing a page that pulls data from another MySQL Database on the same server as my WordPress install.
    I am trying to use a new instance of wpdb but it doesnt seem to be working.

    
    global $wpdb, $crmdb, $current_user;
    $crmdb = new wpdb("db user","Password","DB name","localhost");
    $crmdb->show_errors();
    $crmdb->set_prefix(''); //Tried this with and without this line other DB does not have a prefix.
    $sql= "select * from accounts_cstm where id_c='$crmid'";//SQL to crm db table
    $insur = $crmdb->get_results($sql);
    foreach($insur as $row)
    {
    echo $row->id_c; //id_c is one of the field names.
    }
    //print_r($insur); //tried this to see what all info was being generated...none.
    

    It isnt even giving me an error to go with.
    Any ideas?
    Thanks
    Jamie

Viewing 2 replies - 1 through 2 (of 2 total)
  • @jamie

    you should not create different database for this. you can create new tables in your WordPress db. create your own tables with your preferred prefix and try accessing them using custom query using wpdb object.

    Hope this will help you!

    Thread Starter jamiesw

    (@jamiesw)

    Hi theee,
    Thanks for replying, creating the tables with the wordpress database isn’t an option. The other db is an exisiting crm that is in use. From what I have read online so far what i am trying to do should work.
    Thanks
    Jamie

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Using wpdb to connect to another database’ is closed to new replies.