Title: Database load from other server
Last modified: May 18, 2021

---

# Database load from other server

 *  [dejan08](https://wordpress.org/support/users/dejan08/)
 * (@dejan08)
 * [5 years ago](https://wordpress.org/support/topic/database-load-from-other-server/)
 * 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](https://wordpress.org/support/users/kartiks16/)
 * (@kartiks16)
 * [5 years ago](https://wordpress.org/support/topic/database-load-from-other-server/#post-14434484)
 * 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.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 2 participants
 * Last reply from: [Kartik Shukla](https://wordpress.org/support/users/kartiks16/)
 * Last activity: [5 years ago](https://wordpress.org/support/topic/database-load-from-other-server/#post-14434484)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
