我写了个数据库连接处理类 。。但是我在声明变量在本类调用时候 总是提示空值错误- - 。。顺便请教下构造是这么写的吗?  我查的BAIDU  写构造各种各样的- - 。。请帮忙修正一下。。谢谢。<?
class FunctionClass{
public $user;
public $pass;
public $host;
public $database;
function FunctionClass(){
$this->$database="MyOffice";
$this->$user="ffhelly";
$this->$pass="19861121";
$this->$host="127.0.0.1";
} function FindUser($sql1)
{
$MySql_Server_name ="127.0.0.1";
$MySql_UserName="root";
$MySql_Password="19861121";
$MySql_DataBase="MyOffice";
//$link = mysql_connect($MySql_Server_name, $MySql_UserName,$MySql_Password);
$link = mysql_connect($this->$host, $this->$user,$this->$pass);
mysql_query("set names 'gb2312'");
$res=mysql_db_query($this->$database,$sql1);
return $res;
}
}
?>

解决方案 »

  1.   

    Fatal error: Cannot access empty property in D:\AppServ\www\Function.php on line 8这是错误提示
      

  2.   

    我这样写  也是同样的错误也是Cannot access empty property   求解。。<?
    class FunctionClass{
        public $user="ffhelly";
        public $pass="19861121";
        public $host="127.0.0.1";
        public $database="MyOffice";
    /*
        function FunctionClass(){
            $this->$database="MyOffice";
            $this->$user="ffhelly";
            $this->$pass="19861121";
            $this->$host="127.0.0.1";
        }
    */
        function FindUser($sql1)
        {
            $MySql_Server_name ="127.0.0.1";
            $MySql_UserName="root";
            $MySql_Password="19861121";
            $MySql_DataBase="MyOffice";
            //$link = mysql_connect($MySql_Server_name, $MySql_UserName,$MySql_Password);
            $link = mysql_connect($this->$host, $this->$user,$this->$pass);
            mysql_query("set names 'gb2312'");
            $res=mysql_db_query($this->$database,$sql1);
            return $res;
        }
    }
    ?>
      

  3.   

    $this->$host 改成 $this->host, 类似全改