How to use wpdb to connect to a separate database?
Assuming the second database has the same login information as the main WP one you can even use the predefined constants from wp-config.php to avoid hardcoding the login information. no one has said this so I thought I’d add an even easier way..
How to connect to a second database in WordPress?
Connecting to a second database is easy in WordPress, you simply create a new instance of the WPDB class and use it the same way you would use the standard $wpdb instance we all know and love.
Which is WP database class do you use?
WP’s database class is a customized version of Justin Vincent’s ezSQL. If you like the interface and you’re wanting to do a site that’s not WordPress-based, you might want to check it out: http://justinvincent.com/ezsql
How to replace the wpdb class in WordPress?
It is possible to replace this class with your own by setting the $wpdbglobal variable in wp-content/db.php file to your class. The wpdbclass will still be included, so you can extend it or simply use your own. Top ↑ More Information #More Information An instantiated wpdbclass can talk to any number of tables, but only to one database at a time.
How to create wpdb global object in WordPress?
Using the $wpdbglobal object #Using the $wpdbglobal object WordPress provides a global object, $wpdb, which is an instantiation of the wpdbclass. By default, $wpdbis instantiated to talk to the WordPress database.
How to specify authentication database and target database separately?
/database Optional. The name of the database to authenticate if the connection string includes authentication credentials in the form of username:password@. If /database is not specified and the connection string includes credentials, the driver will authenticate to the admin database. Make sure you have a user in test database.