Bypassing the Database Limit on Hosting
As you already know, the number of databases on virtual hosting is usually limited. Typically, it is equal to the number of sites.
However, there are situations when we need more databases. Let's discuss what these situations are and how to bypass the limit on the number of databases.
So. Let's assume we have the cheapest tariff, in which we can create only one site and, accordingly, one database.
However, we can create one second-level site, but any number of subdomains. For example, on the main domain, we can have an online store, and on a subdomain - a forum.
It turns out that we need two databases. And just because of this, we will have to take a more expensive tariff. But there is a workaround.
The essence of the workaround is as follows. Both of our sites will live in one database. But, so that the table names do not conflict, we will give them prefixes.
For example,
we will start the table names of the store with
shop_, and the table names
of the forum with forum_.
However, usually for brevity,
prefixes are made with two letters,
in our case it could be
sh_ and fr_.
Of course, changing table names throughout the entire code can cause some inconvenience. Therefore, when developing a site, it is better to foresee the possibility of such a situation and not hardcode table names, but store them somewhere in one place, so that they can be easily changed.
Or, immediately provide in our code for the presence of a prefix and everywhere in SQL queries add the prefix before the table name. The prefix itself will be stored somewhere in one place - in our site's configuration. Thus, we can easily change it to the one we need.
Think about the code that you will write in your project to support table prefixes.