WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have two databases on my server, and wanted to know is there a way to access both databases from wordpress? My thought is adding the second set of credentials to the wp-config.php.

share|improve this question
up vote 3 down vote accepted

You can easily set up another $wpdb object to access your other database.

$mydb = new wpdb(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST);

That, of course, uses the default connection credentials but if you defined different constants and used those, is should work just fine.

If this other database is not a WordPress database, you won't have some of the functionality offered by the wpdb class but the basics should work if you write the SQL.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.