我有个奇怪的问题。我在根目录中有一个文件index.php,在根目录中有2个文件包含目录。
根> index.php,包括 包含> config.php,db.php
在include/db.php中,我定义了如下MySQL连接参数:
$hostname = 'localhost';
$username = 'root';
$password = '';
$dbname = 'mydb';然后,我在include/config.php中包含了这个文件:
include 'db.php';最后,我将include/config.php包含在index.php中。
我遇到的问题是,在运行index.php时,我无法访问数据库变量。它们只有在我运行include/config.php.时才可用。但是当我将这些变量包含在index.php中时,我希望必须在这两个文件中包含所有定义的变量。
有什么问题吗?
发布于 2014-05-26 12:19:56
如果您已经将config.php包含在index.php中,db.php包含在config.php中。那么index.php应该是:include 'include/config.php';和config.php应该是:include 'include/db.php';
https://stackoverflow.com/questions/23869170
复制相似问题