I am trying to convert my PHP application to support multi tenancy(SaaS). I came across this article and modified my existing config.php file as below.
<?php
$data = explode('.',$_SERVER['SERVER_NAME']);
if (!empty($data[0])) {
$subdomain = $data[0];
}
define('SITE_DB_SERVER','localhost');
define('SITE_DB_PORT','3306');
define('SITE_DB_USERNAME','root');
define('SITE_DB_PASSWORD','mysql');
define('SITE_DB_NAME','central');
$sitedbh = mysql_connect(SITE_DB_SERVER.':'.SITE_DB_PORT,SITE_DB_USERNAME,SITE_DB_PASSWORD);
$sitemysql = mysql_query('select id,dbusername,dbpassword from central.client where subdomain = '.$subdomain.'');
$appdata = mysql_fetch_row($sitemysql);
if (empty($appdata['id'])) {
echo "Oops! Sorry, we are unable to find you! Please email us at support@mydummyapp.com";
exit();
}
define('DB_HOSTNAME', '127.0.0.1');
define('DB_PORT', '3306');
define('DB_USERNAME', 'root');
define('DB_PASSWORD', 'mysql');
define('DB_DATABASE', 'myapp_'.$appdata['id']);
define('LAST_ACTIVITY_TIMEOUT', '3600');
define('SESSION_RENEG_TIMEOUT', '600');
define('USE_DATABASE_FOR_SESSIONS', 'true');
define('CSP_ENABLED', 'false');
date_default_timezone_set('America/Chicago');
?>
When trying to run my application I am facing "Warning: mysql_fetch_row() expects parameter 1 to be resource, boolean given in /myapp_path/config.php on line 19" error. Please refer the screenshot. I tried some solutions available for the past 10 hours and nothing worked for me. Kindly help me in getting this up and running.