WordPress is an amazing open-source CMS that now powers 40% of websites on the internet and is still growing. However, like any system, it has its drawbacks. Most notably the system is often frowned upon by developers who might prefer to build a homebrew solution from scratch using their favorite programming language or something trendy. One of the largest complaints is that WordPress only works with its native relational database which is typically MySQL or MariaDB and does not play well with secondary databases or a large array of relational databases distributed over several servers. When it comes to enterprise solutions, this can cause friction among stakeholders who want to incorporate their existing databases and systems but want to use WordPress as their front-end and content management system.
One solution you might consider would be to make a headless WordPress system where the REST API of WordPress is used to power a hybrid solution of WordPress’ powerful content management features and a non-PHP environment the developer desires. In a headless system WordPress is essentially the backend and the front-end will be the other coding language the developer opts to use such as Vue or React. While headless systems have been proven to eliminate concerns around load time and give a developer freedom to build a website without using PHP, they can be complicated to build and do not resolve the issue at hand of retrieving data from a secondary, tertiary, or array of relational databases.
If the stakeholders want the project to use WordPress’ front-end features (i.e. themes and plugins) there are other options at your disposal. We are going to examine a few different ways to use the stock WordPress with a secondary.
1. As a Business Intelligence Dashboard
If your secondary database is filled with internal data that information can now be easily and beautifully displayed inside of WordPress using a plugin called WP Business Intelligence. This plugin takes out the effort of making charts and graphs from your data and makes it as simple as a SELECT query.
The plugin allows any developer on WordPress to quickly connect to a separate MySQL, MariaDB, MS SQL, or PostgreSQL database and then to quickly transform information from that database into charts and graphs or into a full business intelligence dashboard.
2. As a User Login System
Your secondary database might be the login system of a corporate internal communication application, a separate shopping cart, a rewards system, a mobile app, or something else your enterprise uses that requires employees or customers to login to and retains their login data. You can grant those users the ability to login to a separate WordPress website using the plugin External Login Plugin.
This plugin allows users of your other application to visit your WordPress powered site and click the “login” button to login to the website. Notably uses will not be automatically logged in to your site, while this plugin offloads the standard WordPress login system to use a different, secondary database, it does not create a Single Sign On server (SSO) for your users. They will still have to use their login credentials to access the features of your WordPress site. However, if you are unable to build out an SSO or a headless WordPress implementation on a JAMstack, this is a great second option for developers.
3. Connect Your WordPress to an Arbitrary Number of Relational Databases
Your project may require connection to dozens, hundreds, or even thousands of databases with millions of tables on servers located at various datacenters around the globe. In this case you will want to use the HyperDB plugin for WordPress. Built by the Automattic team (the creators of WordPress and WordPress.com) the HyperDB plugin is based on the methodology used by the WordPress.com which handles millions of database tables across thousands of relational databases. The system is constantly balancing resources by migrating tables between database and updating their location inside of a central database which acts as a sort of index allowing the system to quickly find where a table is currently located.
[insert HyperDB screenshot]
4. To Access Other Databases
If none of those plugins works for your needs and you only have one database, then you can connect it to your WordPress site by adding a second instantiation of the wpbd class. This takes a little bit of coding know how, specifically PHP, and understanding how WordPress works.
There are two articles on how to do this, both are slightly aged but should point you in the right direction.
- WordPress: Connecting to an External / Secondary Database
- How to Connect Another Database in WordPress
These are exciting times for developers. As WordPress becomes a more and more dominant part of the web, developers will need more and more tools to integrate the CMS into their current operations many of those tools may not yet exist and will need to be created. Hopefully, the above information helps you expand your WordPress capabilities by integrating a secondary database without having to build something from scratch.