Not*_*mon 1 php variables include
好吧,所以这是非常基本的东西,我知道当有人告诉我答案时我会觉得很傻,但我不能为我的生活弄清楚为什么下面的代码不起作用:
index.php文件:
<?php include('config.php'); //this works fine. variables in this file are reached correctly - $_MYSQL is defined there ?>
<?php include($_MYSQL); ?>
<?php echo ($fruit);?>
Run Code Online (Sandbox Code Playgroud)
db_config.php(这是$ _MYSQL链接到的,这没问题):
<?php
$fruit = "apple";
echo($fruit);
?>
Run Code Online (Sandbox Code Playgroud)
为完整性config.php看起来像:
<?php
$_MYSQL = 'http://'.$_SERVER['HTTP_HOST'].'/public_html/db_config.php';
$BASE_URL = 'http://'.$_SERVER['HTTP_HOST'].'/public_html/Opto10/';
?>
Run Code Online (Sandbox Code Playgroud)
因此,名称暗示代码是要联系此db_config.php然后连接到数据库,但由于某种原因,db_config文件中的变量似乎不会传递给index.php.奇怪的是include('config.php'); 工作完全正常,但在上面我在index.php中显示的代码"echo($ fruit);" 不打印任何东西.db_config.php中的同一行虽然(但我猜它确实意味着它包含在内).不知何故,变量不会传递.您知道,如果这有所不同,db_config.php文件位于当前目录的父文件中.
我很困惑,任何帮助都非常受欢迎.提前致谢,
西蒙
你所拥有的就是我所有的PHP代码.