Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

Accessing another database FROM another server through wpdb.

Hello, I'm kinda new here. So here's my situation:

I have a woocommerce website, but with a twist, I have to get the price (via SKU) from another database, from another server, which I don't have access to. (But they have already whitelisted my static IP)

How can I connect to their database without ruining my connection to my own database?

So here's what I tried. (I'm trying to connect to the database first.) I'll replace the real credentials. Remote = another database from another server

global $wpdb;
$newdb = new wpdb('remote_db_username', 'remote_db_pass', 'remote_dbname', '10.41.1.47');

if ( $newdb->check_connection() ) {
    echo "Hey, we connected, alright!";
}
else {
    echo "Hey... not connected....... now what?!";
}

    //Going back to my own DB
global $wpdb;
$newdb = new wpdb('my_dbuser', 'my_db_pass', 'my_dbname', 'localhost');

Please help me what I'm doing wrong. Thanks :)

1 Answer

I have also tried adding the port which is 3306 on 10.41.1.47:3306