打开index.php文件里面调用<?php require_once('../conf.inc.php');?>conf.inc.php代码:
--------------------------------------------------------
   include_once('appl/controller/interface.inc.php');
   include_once('appl/model/mysql.class.php'); 
   main::init_db();
--------------------------------------------------------
interface.inc.php代码:
---------------------------------------------------
class main
  {
    private $DB_config = array();

function init_db()
  {
$db = new Mysql($DB_config[0]='localhost',$DB_config[1]='root',$DB_config[2]='root',$DB_config[3]='cf');
$db->connect();
  }
  }
-----------------------------------------------------mysql.class里的构造函数  
public function __construct($dbhost,$dbuser,$dbpwd,$dbname)
   {
       $this->$DB_HOST = $dbhost;
   $this->$DB_HOSTUSER = $dbname;
   $this->$DB_HOSTPWD = $dbpwd;
   $this->$DB_NAME = $dbname;
            }
--------------------------------------------------------------------------------------问题就是$dbhost,$dbuser,$dbpwd,$dbname 这四个变量都是空值,请问怎么回事?

解决方案 »

  1.   

    $this->$DB_NAME = $dbname;
    $this->DB_NAME = $dbname;//其他类似
      

  2.   

    出现
    Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'cf'@'localhost' (using password: YES) in C:\wwwroot\cf\appl\model\mysql.class.php on line 51
    Access denied for user 'cf'@'localhost' (using password: YES)请问怎么回事
    -------------------------------------------------------------------- 
    //connect代码
    public function connect()
       {
           $this->DB_LINK = mysql_connect($this->DB_HOST,$this->DB_HOSTUSER,$this->DB_HOSTPWD) or die(mysql_error());
       mysql_select_db($this->DB_NAME,$this->DB_LINK);
       mysql_query("SET NAMES 'gbk'");
       }
      

  3.   

    $db = new Mysql($DB_config[]='localhost',$DB_config[]='root',$DB_config[]='root',$DB_config[]='cf');
    怎么第二个值怎么改都是cf啊。我没搞明白
      

  4.   

    $db = new Mysql($DB_config[]='localhost',$DB_config[]='root',$DB_config[]='root',$DB_config[]='cf');localhost是数据库服务器地址
    第一个root是数据库用户名
    第二个root是数据库密码
    最后一个cf是数据命名。改你需要改的就可以了。
      

  5.   


    我知道代码自己写的,但是我的第二值我用echo输出查看,它值是cf就是不知道怎么回事?
      

  6.   

    看看  $DB_config  這個數組裏邊 的值是否正確