WordPress: Connecting to an External / Secondary Database
· 2 min. read
$wpdb
can only access and manipulate the WordPress database. How may I do the same for another database with different credentials?
WordPress provides developers with a class of functions to manipulate the database and this is particularly useful for custom plugins and/or themes. Developers may interface - create, read, write and/or delete data - with the WordPress database via the global $wpdb
object; however, to interact with another database (an external/secondary one) a new instantiation of the wpdb class is required. In WordPress' codex, hyperdb is recommended as the solution "for extremely complicated setups with many databases". If however, you are not too keen on using someone else's plugin it is pretty simple to create your own custom database object using the wpdb class.