【发布时间】:2014-02-20 09:45:02
【问题描述】:
我在本地和远程设置中有相同的 wp-config。
下面的代码检查用户是在加载站点的本地版本还是实时版本,并使用适当的数据库凭据:
/*
* Unified variables
*/
$hostname = 'localhost';
$chartset = 'utf8';
*etcetc....
/*
* Check for the current environment
*/
if ($_SERVER["HTTP_HOST"] === 'example.dev') {
$db_name = 'example';
$user_name = 'root';
$password = 'root';
} else
{
$db_name = 'remote_db_name';
$user_name = 'remote_db_user';
$password = 'remote_db_pw;
}
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', $db_name);
/** MySQL database username */
define('DB_USER', $user_name);
//etc....
这个有效。但是,如果我将 if 命令翻转过来,那么它的
if ($_SERVER["HTTP_HOST"] === 'example.com') {
$db_name = 'example';
$user_name = 'root';
$password = 'root';
} else
{
$db_name = 'remote_db_name';
$user_name = 'remote_db_user';
$password = 'remote_db_pw;
}
它适用于几种不同的设备和连接,但对于我的客户端它不再适用。任何想法为什么会这样?
我需要相反,因为我正在使用其他设备测试我的设计,这些设备的网址如下: http://example.dev.192.168.1.3.xip.io 如果本地开发的所有内容(例如 example.dev 和 http://example.dev.192.168.1.3.xip.io)都是 if-else 中的“else”-case,那就更好了。
什么可能导致我的客户端出现数据库错误?他已经尝试了几种设备和连接,如果实时服务器处于“其他”情况而不是
if ($_SERVER["HTTP_HOST"] === 'example.com') {
【问题讨论】:
标签: php mysql database wordpress if-statement