包括,全局和类都在一个? [英] include, globals and classes all in one?
问题描述
这里的交易是:
我有一个config.php文件,其中我设置了一些var'' ,用于
整个网站。例如:
$ db_host =" localhost" ;;
然后我还有一个类,应该处理所有数据库
函数。在这个课程中,我尝试从我的配置文件中恢复var',
但是这似乎不起作用。我试着在构造函数和普通函数中放入以下
语句,但var的
输出总是空的。
include(" config.php");
global $ db_host;
echo" db_host的值:"。$ db_host;
现在,我有点怀疑它可能与我正在使用课程的事实有关,但我不知道怎么了。通常我应该
能够使用config.php文件中的值,对吗?
greetz
< T !M>又名wEEdpEckEr
Hi,
here''s the deal:
I have a config.php file in which I have set a few var''s, to use in the
whole site. E.g.:
$db_host = "localhost";
Then I also have a class, which is supposed to handle all database
functions. In this class I try to recover the var''s from my config file,
but this just doesn''t seem to work. I tried to put the following
statements in the constructor as well as in a plain function, but the
output of the var is always empty.
include("config.php");
global $db_host;
echo "value of db_host: ".$db_host;
Now, I have a slight suspicion that it might have to do with the fact
that I''m using classes, but I don''t know what''s wrong. Normally I should
be able to use the values from the config.php file, right?
greetz
<T!M> aka wEEdpEckEr
推荐答案
db_host =" localhost" ;;
然后我也有一个班级,应该处理所有数据库
函数。在这个课程中,我尝试从我的配置文件中恢复var',
但是这似乎不起作用。我试着在构造函数和普通函数中放入以下
语句,但var的
输出总是空的。
include(" config.php");
global
db_host = "localhost";
Then I also have a class, which is supposed to handle all database
functions. In this class I try to recover the var''s from my config file,
but this just doesn''t seem to work. I tried to put the following
statements in the constructor as well as in a plain function, but the
output of the var is always empty.
include("config.php");
global
db_host;
echo" value db_host:"。
db_host;
echo "value of db_host: ".
db_host;
现在,我有点怀疑它可能与事实有关
我正在上课,但我不知道什么是错的。通常我应该
能够使用config.php文件中的值,对吗?
greetz
< T !M>又名wEEdpEckEr
db_host;
Now, I have a slight suspicion that it might have to do with the fact
that I''m using classes, but I don''t know what''s wrong. Normally I should
be able to use the values from the config.php file, right?
greetz
<T!M> aka wEEdpEckEr
这篇关于包括,全局和类都在一个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!