我搜索了谷歌,stackoverflow,但所有与php
框架相关的主题都不是核心php
,我想知道根据子域更改数据库的最佳解决方案是什么。我有一个多语言网站,我想使用单一源代码,但有不同的子域名,只需根据子域名更改数据库。
这是我的代码:
$domain = $_SERVER['HTTP_HOST'];
$sub = array_shift((explode('.', $domain)));
if ($sub == 'tr') {
$servername = "localhost";
$username = "db_tr";
$password = "xxxxx";
$dbname = "xxxx";
} else if ($sub == 'gb') {
$servername = "localhost";
$username = "db_gb";
$password = "xxxxx";
$dbname = "xxxx";
} else if ($sub == 'us') {
$servername = "localhost";
$username = "db_us";
$password = "xxxxx";
$dbname = "xxxx";
} else if ($sub == 'ca') {
$servername = "localhost";
$username = "db_ca";
$password = "xxxxx";
$dbname = "xxxx";
} else {
$servername = "localhost";
$username = "db_all";
$password = "xxxxx";
$dbname = "xxxx";
}
所以我有两个问题:
sql
注入,黑客攻击或其他安全问题。