How to use multiple database in wordpress?

It is possible but you must manually create a new instance of the wpdb class with right settings for your other database.

Quote from the wpdb Codex page:

The $wpdb object can talk to any number of tables, but only one
database: the WordPress database. In the rare case you need to connect
to another database, you will have to instantiate your own object from
the wpdb class with the appropriate connection details. For extremely
complicated setups with many databases, consider using hyperdb
instead.

Leave a Comment