简体   繁体   中英

How to handle different DB based on different config files for each user?

I'm facing a new challenge at work and, as happens to me with all challenges, I'm a bit excited but I stucked a little bit at planning.

We have a CRM solution we are planning to sell to other companies within our servers. That said, I thought that, to avoid having a overpopulated database, we should have separated databases for each company that sign up in the application.

So, every company would have a subdomain like mycompanie.mywonderfullcrm.com and so, that URL points to a folder that should be something like \\root_folder\\clients\\mycompanie\\ and within that, it only would be the "config" file which then points to the correct database.

From my point of view, that allows to update easily the tool to fix bugs or add new features.

My question is... how could I use core application files with different config files in different folders?

you could use the php system variable $_SERVER['HTTP_HOST'] to determine to wich company the http client is refering. then you could load the config file from your folder. here a short untested example:

$parsedUrl = parse_url($_SERVER['HTTP_HOST']);  
$host = explode('.', $parsedUrl['host']);  
$subdomain = $host[0]; 

/* include config here */
include_once('\root_folder\clients\'.$subdomain.'\config.php'); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM