• dejan08

    (@dejan08)


    Hello guys,

    I have a e-commerce site build with WP, on one server where i have Cpanel and WHM access. Thing that i need is to that my site load database from another server? Can someone help me how to connect that two servers or how to load just database from other server? On my server where domain is and my website i have MSQL, and on other server from which i want to syncronize or have the same database on my site is PostgreSQL. Is that problem? To be short, i want to my WP site have the same database like other server, and when something is changed in database, automaticly is reflected on my website.

    Best Regards
    Thank You

Viewing 1 replies (of 1 total)
  • Kartik Shukla

    (@kartiks16)

    Hello,

    You can connect second database, by adding some code in your theme functions.php, create new instance of wpdb.

    function connect_another_db() {
        global $seconddb;
        $seconddb = new wpdb(USERNAME, PASSWORD, DATABASE_NAME, HOSTNAME);
    }
    add_action('init', 'connect_another_db');

    Example :

    global $seconddb;
    $prefix = 'wp2_'; // here 'wp2' is the table prefix of second database
    $user_count = $seconddb->get_var( "SELECT COUNT(*) FROM $prefix"."users" );
    echo "<p>User count is {$user_count}</p>";

    You can also see a plugin called HyperDB if that helps.

    Thanks.

Viewing 1 replies (of 1 total)

The topic ‘Database load from other server’ is closed to new replies.