• You MUST read the Babiato Rules before making your first post otherwise you may get permanent warning points or a permanent Ban.

    Our resources on Babiato Forum are CLEAN and SAFE. So you can use them for development and testing purposes. If your are on Windows and have an antivirus that alerts you about a possible infection: Know it's a false positive because all scripts are double checked by our experts. We advise you to add Babiato to trusted sites/sources or disable your antivirus momentarily while downloading a resource. "Enjoy your presence on Babiato"

Need help in Connecting the second host & database in WordPress

vijay1

Well-known member
Trusted Uploader
Apr 25, 2020
294
637
93
31
IN
Hi,
I'm trying to connect a remote database in WordPress.
I have some data on the remote server (1.1.1.1) which I want to access in WordPress installation.
Currently, the WordPress database is connected to serve(2.2.2.2)
what I found on the internet is to connect to another database from the same server or host.
PHP:
function connect_another_db() {
    global $seconddb;
    $seconddb = new wpdb(USERNAME, PASSWORD, DATABASE_NAME, HOSTNAME);
}
add_action('init', 'connect_another_db');
How can i connect remote host ...?

Thanks in advance
 
Why not use the db ip address and add it under wp-config.php instead of localhost. That would be the easiest. Speed and security might be a primary concern unless you harden the database server since you need to open ports for external connections. Best to restrict access to your wp installed server ip. You can also try HyperDB: [COLOR=var(--theme-link-color)]https://wordpress.org/plugins/hyperdb/[/COLOR] It allows multiple databases, also read/write replicas or master / slave.

 
AdBlock Detected

We get it, advertisements are annoying!

However in order to keep our huge array of resources free of charge we need to generate income from ads so to use the site you will need to turn off your adblocker.

If you'd like to have an ad free experience you can become a Babiato Lover by donating as little as $5 per month. Click on the Donate menu tab for more info.

I've Disabled AdBlock