Title: Two WordPress databases
Last modified: August 28, 2022

---

# Two WordPress databases

 *  Resolved [kklo](https://wordpress.org/support/users/kklo/)
 * (@kklo)
 * [3 years, 8 months ago](https://wordpress.org/support/topic/two-wordpress-databases/)
 * Hi,
 * Is it possible to have two WordPress databases in a single template and domain?
   
   Example: An ecommerce veterinary products and a veterinary clinic.
 * The question is that they are different users and some different pages.
 * Or would it be better and easier to use a user role manager and page access control?
 * Thanks
 * kklo
    -  This topic was modified 3 years, 8 months ago by [Jan Dembowski](https://wordpress.org/support/users/jdembowski/).

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [3 years, 8 months ago](https://wordpress.org/support/topic/two-wordpress-databases/#post-15960388)
 * It’s possible. You’d create a new `wpdb` class object using the other DB’s credentials.
   You can then query directly with native PHP mysqli functions, or swap wpdb connection
   objects into the global `$wpdb`, which is the default DB connection. Whatever
   DB that global is connected to is what WP thinks of as its own. Once you’ve made
   a query to the alternative DB, swap the original object back into the global 
   to restore normal operation.
 *  Thread Starter [kklo](https://wordpress.org/support/users/kklo/)
 * (@kklo)
 * [3 years, 8 months ago](https://wordpress.org/support/topic/two-wordpress-databases/#post-15960663)
 * Hi, [@bcworkz](https://wordpress.org/support/users/bcworkz/)
 * Great thanks a lot.
    I hope to get this setup right.
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [3 years, 8 months ago](https://wordpress.org/support/topic/two-wordpress-databases/#post-15964164)
 * I misspoke slightly, apologies.
 * > You can then query directly with native PHP mysqli functions
 * While this is always true, what I should have said is you can then query the 
   alternate DB using the new `wpdb` object’s methods.
    [https://developer.wordpress.org/reference/classes/wpdb/](https://developer.wordpress.org/reference/classes/wpdb/)
 *  Thread Starter [kklo](https://wordpress.org/support/users/kklo/)
 * (@kklo)
 * [3 years, 8 months ago](https://wordpress.org/support/topic/two-wordpress-databases/#post-15965009)
 * ok,
    Thanks

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Two WordPress databases’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 4 replies
 * 2 participants
 * Last reply from: [kklo](https://wordpress.org/support/users/kklo/)
 * Last activity: [3 years, 8 months ago](https://wordpress.org/support/topic/two-wordpress-databases/#post-15965009)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
