function &getconnect()
{
$con=mysql_connect($this->localhost,$this->user,$this->password);
return $con;
}
这个不是定义?

解决方案 »

  1.   

    在类内部调用成员函数应该用$conn = $this->getconnect();而不应该象你这样$conn = getconnect();
      

  2.   

    还有就是<?php ... ?>最好用这种标记,不要用<? ... ?>
      

  3.   

    $conn=getconnect();
    改成
    $conn=$this->getconnect();
      

  4.   

    <?
    class DB
    {
    var $database;
    var $localhost;
    var $user;
    var $password;
    var $sql;
    function DB($localhost,$user,$password,$database)
    {
    $this->localhost=$localhost;
    $this->user=$user;
    $this->password=$password;
    $this->database=$database;
    }
    function &getconnect()
    {
    $con=mysql_connect($this->localhost,$this->user,$this->password);
    return $con;
    }
    function _select_db()
    {
    $conn=$this->getconnect();
    mysql_select_db($this->database,$conn);
    }
    function  &query($sql)
    {
    $this->sql=$sql;
    $conn=$this->getconnect();
    $result=mysql_query($this->sql,$conn);
    return $result;
    }
    }
    ?>
    <?
    $t=new DB('localhost','user','','mysql');
    $conn=$t->getconnect();
    $t->_select_db();
    $sq="select * from x";
    $r=$t->query($sq);
    while($re=mysql_fetch_object($r))
    echo $re->a;
    ?>
    Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in c:\appserv\www\ttt.php on line 41
    还是错误啊。。表 x存在。也有值。。为何这样
      

  5.   

    You have a table named "x" in the database "mysql" ???