這裏是你的解決方案。建立與相應的客戶端ID的所有鏈接,並更改爲database.php像
if (isset($_REQUEST['clid'])) {
$efg = (int) $_REQUEST['clid'];
} else {
die('wrong URL');
}
$dbh = new PDO('mysql:host=localhost;dbname=client_db,client_dbuser,clientdb_pass');
$sql = 'SELECT db_username,db_name,db_pass FROM clients WHERE id=?';
$sth = $dbh->prepare($sql);
$sth->execute(array($efg));
$d_result = $sth->fetchAll(PDO::FETCH_ASSOC);
if (count($d_result) < 1) {
die('Wrong client');
}
$active_group = 'default';
$query_builder = TRUE;
$db['default'] = array(
'dsn' => '',
'hostname' => 'localhost',
'username' => $d_result[0]['db_username'],
'password' => $d_result[0]['db_pass'],
'database' => $d_result[0]['db_name'],
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => TRUE,
'db_debug' => TRUE,
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_unicode_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);
我收集$d_result[0]['db_username'], $d_result[0]['db_pass']
等從客戶數據庫。你可以從會話或其他任何東西中拿走它。希望能幫助到你。
你爲什麼需要這樣做? – Nassim
每個公司都有自己的數據庫,並且用戶登錄提供數據庫名稱。 – dutchlab
然後我想最好是將數據庫名稱放在會話中,然後調用它或從會話中重命名它,這樣做更有意義 – Nassim