Need help in Connecting the second host & database in WordPress

vijay1

Well-known member
Trusted Uploader
Apr 25, 2020
251
307
63
32
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
 

ckeeper

Well-known member
Nov 8, 2019
623
376
63
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.

 

About us

  • Our community has been around for many years and pride ourselves on offering unbiased, critical discussion among people of all different backgrounds. We are working every day to make sure our community is one of the best.

Quick Navigation

User Menu