WordPress uses MySQL for its database management system. ... WordPress uses PHP, using SQL query within the PHP markup, as the language of instruction to CRUD (Create, Read, Update, and Delete) data from the MySQL database. The database is an essential part of WordPress. It is the backbone that stores all core information.
When you need to connect another database, create an instance of the wpdb class. Doing so, you get access to all available methods of wpdb class. The user can use these class methods directly to interact with the external database. For getting started, you should have the credentials of an external database. As said, it needs to create an instance of wpdb class. This instance should be available throughout the WordPress application. For this, add the below code in functions.php file.