未定义的变量包括php文件

时间:2013-10-23 21:15:24

标签: php

如果问题已经多次提出,我很抱歉,但我无法理解。

我的网站结构是:


    • 表格
      • FormHouse
      • FormUser

在根文件夹中,我有一个文件classes.php

<?php
  include("config.php");
  include("class.mysql.php");
  ... code ...
?>

此文件包含在文件根目录/ Forms / FormHouse / FormHouse.php

<?php 

  include('../../classes.php');

  session_start();

  print_r(get_included_files());

  $db = new MySQL("$db_name", "$db_user", "$db_psw", "$host");
  if (!$db) 
  die($db->Error());

?>

我也试试:

include(dirname(__FILE__) . '\..\..\classes.php');

这里我在$ db_user,$ db_name,$ db_psw,$ host上获得“Undefined variable”。

查看包含的文件,classes.php存在:

Array 
( [0] => D:\xampp\htdocs\site\Forms\FormHouse\FormHouse.php 
  [1] => D:\xampp\htdocs\site\classes.php 
  [2] => D:\xampp\php\pear\Config.php 
  [3] => D:\xampp\php\pear\PEAR.php 
  [4] => D:\xampp\php\pear\PEAR5.php 
  [5] => D:\xampp\php\pear\Config\Container.php 
  [6] => D:\xampp\htdocs\site\class.MySQL.php 
) 

为什么会这样?包含订单事项?

1 个答案:

答案 0 :(得分:0)

添加

chdir(dirname(__FILE__));

在classes.php中包含之前解决了这个问题。