Remotely connect to another WP Database
I’ve been working on a plugin which I’m going to pass onto a couple of websites. These websites have joined a “Network” we have made and the plugin adds a header bar and menu from the “Hub” website.
Before I ask the question, here is what I have so far….
DB_User = Database Username
DB_Pass = Database Password
DB_Name = Database Name
// Save Current Database details
$wpdb_old = wp_clone($GLOBALS[‘wpdb’]);
$wpdb_new = &$GLOBALS[‘wpdb’];
// Open Remote Connection
$wpdb_new = new wpdb(‘DB_User’,’DB_Pass’,’DB_Name’,’localhost’);
// Get Menu
wp_nav_menu( array( ‘sort_column’ => ‘menu_order’, ‘container_class’ => ‘tpk_plugin_header_menu’, ‘menu_class’ => ‘tPKmenu’, ‘menu’ => ‘tPK_plugin’ ) );
// Reset the query
// Put the old wpdb back
$wpdb_new = $wpdb_old;
The code above works perfectly fine, as long as the website using it is on the same web server as the “Hub” website. Most of the websites that will use this code are on the same server and already using this code perfectly. Some of them are not and display no menu
I know where the problem is, I just can’t work out what I need to replace it with.
$wpdb_new = new wpdb(‘DB_User’,’DB_Pass’,’DB_Name’,’LOCALHOST’);
What do I change “Localhost” to, that will allow sites running the plugin on another website to be able to access the data?
I tried the IP address of the SQL server and it has little sucess. I’ve made sure that any sites I’m working with, have permission for remote access, but still nothing.
What am I missing?
- The topic ‘Remotely connect to another WP Database’ is closed to new replies.