【发布时间】:2009-09-22 13:41:15
【问题描述】:
我正在将 PHP 站点从开发服务器移至生产服务器并测试新的数据库连接。我有一个config.php 页面,只有这个(但有真实数据):
<?php
// Database Constants
defined('DB_SERVER') ? null : define('DB_SERVER', 'xxx.xxx.xxx');
defined('DB_PORT') ? null : define('DB_PORT', 'yyy');
defined('DB_USER') ? null : define('DB_USER', 'zzz');
defined('DB_PASS') ? null : define('DB_PASS', 'abcdefg');
defined('DB_NAME') ? null : define('DB_NAME', 'lmnop');
?>
然后我有initialize.php,它包含我所有的define() 常量,并调用我所有的类。
<?php
// Define core paths
// DIRECTORY_SEPARATOR is a PHP pre-defined constant
// (\ for Windows, / for Unix)
defined('DS') ? null : define('DS', DIRECTORY_SEPARATOR);
defined('SITE_ROOT') ? null : define('SITE_ROOT', 'http://...etc');
defined('LIB_PATH') ? null : define('LIB_PATH', SITE_ROOT.'/_includes');
// load config file first
require_once(LIB_PATH."/config.php");
etc...
?>
到目前为止,一切都很好。 (顺便说一句,我故意使用 URL 而不是 DIR 路径。)
但是当我创建一个test.php 页面来运行查询时,我收到了一个错误,即找不到 DB_SERVER。我可以在config.php 中回显某些内容,它将出现在test.php 的页面顶部,因此它正在调用config.php 文件。这是真正的疯狂踢球者:
当我从config.php 复制所有内容并将其粘贴到initialize.php 时,不要更改任何内容,然后注释掉config.php 文件...查询有效。出于某种原因,它不允许我从config.php 中提取这些变量定义。
有人知道为什么吗?
【问题讨论】:
-
错误信息到底是什么意思?
-
顺便说一句,如果您的配置文件检查是否定义了常量,则无需使用
require_once,它很慢且没有必要。