我正在开发一个应用程序,并使用一个子文件夹作为测试域。
http://mywebsite/testing-folder
我的dbconfig位于:
http://mywebsite/testing-folder/lib/dbconfig.php
如果我包含来自以下位置的文件:http://mywebsite/testing-folder/userarea/profile
有了相对路径就可以了。如果我将其包含在一个直接路径中,它会抛出一个错误:
FATAL ERROR: Call to a member function prepare() on a non-object in...
$root = 'http://mywebsite/testing-folder/';
include '../../lib/dbconfig.php'; // This works
include $root.'lib/dbconfig.php'; // This does not
知道为什么吗?
您必须使用文件系统路径,而不是使用URL。所以不是
$root = 'http://mywebsite/testing-folder/';
类似的东西
$root = '/var/www/whatever/';
应该使用。当您在http上包含php时,您的Web服务器将已经解释代码并返回您在那里输出的任何内容(如echo "hello world";
)。如果您的文件仅包含配置,则输出可能为空。
您正在尝试通过HTTP包含文件。这是不对的,您应该包含将本地文件系统路径传递到include
或require
的文件。
你的根可能看起来是这样的:
$root = '/var/www/mywebsite/testing-folder/';