PHP Fatal error:  Call to a member function querysql() on a non-object in /var/www/html/stock/storage/getpointostorage.php on line 25
我的数据库类:dbconnect.php<?php
include("../inc/config.inc.php");
/**
 * @mysql connect class
 * @
 */
class dbconnect {
 /*
  * @param dbhost string hostname for dbserver
  * @param dbuser string dbserver user
  * @param dbpassword string dbserver password
  * @param dbname string database name
  */
  var $dbhost;
  var $dbuser;
  var $dbpassword;
  var $dbname;
  var $link;
  
    /*
     * @构造方法.创建数据库连接
     * 
     */
    function __construct($db_user,$db_password,$db_name,$db_host="localhost"){
        $this->dbuser=$db_user;
        $this->dbpassword=$db_password;
        $this->dbname=$db_name;
        $this->dbhost=$db_host;
    }
    /*
     *  @这个函数用于数据库连接
     */
    function connect(){
        $this->link=mysql_connect($this->dbhost,$this->dbuser,$this->dbpassword) or die("数据库连接发生错误,错误信息是:".mysql_error());
        return $this->link;
    }
    /*
     *
     *  @这个函数用于选择数据库
     */
    function selectdb(){
        mysql_select_db($this->dbname,$this->link);
        @mysql_query("SET NAMES 'UTF-8'");
    }
    /*
     *  @这个函数用于查询SQL语句
     */
    function querysql($sql){
        $this->result=mysql_query($sql);
        if($this->result){//SQL语句执行顺利
           return $this->result;
        }else{//SQL语句执行错误
           echo "查询SQL语句出现错误,错误信息是:<br>".mysql_error();
           return false;
        }
    }
    /*
     *  @这个函数用于根据执行SQL语句结果,取得数据结果集,返回一个数组Array
     */
    function getArray($result){
        return @mysql_fetch_array($result);
    }
    /*
     *  @这个函数用于取得数据库中的第一行
     */
    function getFirst($sql){
        return @mysql_fetch_array($this->query($sql));
    }
    /*
     *  @这个函数用于取得执行SQL语句查询结果集的条数
     */
    function getRows($result){
        return @mysql_num_rows($result);
    }
    /*
     *  @这个函数用于执行SQL更新语句
     */
    function update($sql){
        return @mysql_query($this->$sql);
    }
    /*
     *  @这个函数用于执行SQL插入语句
     */
    function insert($sql){
        return @mysql_query($this->$sql);
    }
    /*
     *  @这个函数用于取得刚插入行的id
     */
    function getid(){ 
        return mysql_insert_id();
    }
    /*
     *   以下函數用來關閉數據庫連接
     */
    function closedb(){
        mysql_close($this->link);
    }
}
$dbcon=new dbconnect(constant("DB_USER"),constant("DB_PWD"), constant("DATABASE_STORE"), constant("DB_HOST"));
$dbcon->connect();
$dbcon->selectdb();
?>
然后在这个类中调用:warehouse.manage.class.include_once("../db/dbconnect.php");
/**
 * Description of warehousemanageclass
 * @該類是用來管理倉庫的物品入庫,出庫,查詢等操作.
 * @author it005
 */
class warehousemanageclass {
    function __construct(){
    }
/**
 *  @method:  getPurchaseGoodsInfoFromPO()
 *  @Description :該函數方法是用來從采購單(PO)中獲取所有正在采購的物品
 *  @用來提示所有應入庫的物品.
 *  @global $dbcon
 *  @author Loo Zhong Chi
 */
    function getPurchaseGoodsInfoFromPO(){
        global $dbcon;
        //Create SQL  獲取PO單中所有物品的SQL語句如下:  $getpo_sql
        $getpo_sql="select * from ".constant("DATABASE_STORE").".".constant("TB_PURCHASELIST")." where state!=1 order by id desc";
        $result=$dbcon->querysql($getpo_sql) or die(mysql_error());
        return @$dbcon->getArray($result);
    }
}
$warehouse=new warehousemanageclass();最后在这个页面中调用getPurchaseGoodsInfoFromPO()就出现这个错误了.getpointstore.phprequire_once("warehouse.manage.class.php");
print_r($warehouse);
$po_row=$warehouse->getPurchaseGoodsInfoFromPO();

解决方案 »

  1.   


    function connect(){
            $this->link=mysql_connect($this->dbhost,$this->dbuser,$this->dbpassword) or die("数据库连接发生错误,错误信息是:".mysql_error());
            //return $this->link;  不用 return 了吧
        }
        /*
         *
         *  @这个函数用于选择数据库
         */
        function selectdb(){
            mysql_select_db($this->dbname,$this->link);
            @mysql_query("SET NAMES 'UTF-8'");
        }1 可以在 warehouse.manage.class 中 继承 dbconnect 类,不过要直接在 dbconnect 类中 实现数据库连接2 要中 warehouse.manage.class. 类中 实例化 dbconnect 类
    function getPurchaseGoodsInfoFromPO(){
            $dbcon=new dbconnect(constant("DB_USER"),constant("DB_PWD"), constant("DATABASE_STORE"),     constant("DB_HOST"));
    $dbcon->connect();
    $dbcon->selectdb();        //Create SQL  獲取PO單中所有物品的SQL語句如下:  $getpo_sql
            $getpo_sql="select * from ".constant("DATABASE_STORE").".".constant("TB_PURCHASELIST")." where state!=1 order by id desc";
            $result=$dbcon->querysql($getpo_sql) or die(mysql_error());
            return @$dbcon->getArray($result);
        }
      

  2.   


    <?php
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    include_once("../db/dbconnect.php");
    /**
     * Description of warehousemanageclass
     * @該類是用來管理倉庫的物品入庫,出庫,查詢等操作.
     * @完成倉庫管理的所有過程和操作.
     * @author it005
     */
    class warehousemanageclass{
    /**
     *  @method __construct()
     *  @Description--構造方法,實例化類方法和變量.
     */
        function __construct(){
        }
    /**
     *  @method:  getPurchaseGoodsInfoFromPO()
     *  @Description :該函數方法是用來從采購單(PO)中獲取所有正在采購的物品
     *  @用來提示所有應入庫的物品.
     *  @global $dbcon
     *  @author Loo Zhong Chi
     */
        function getPurchaseGoodsInfoFromPO(){
            $dbcon=new dbconnect(constant("DB_USER"),constant("DB_PWD"), constant("DATABASE_STORE"), constant("DB_HOST"));
            $dbcon->connect();
            $dbcon->selectdb();
            //Create SQL  獲取PO單中所有物品的SQL語句如下:  $getpo_sql
            $getpo_sql="select * from ".constant("DATABASE_STORE").".".constant("TB_PURCHASELIST")." where state!=1 order by id desc";
            $result=$dbcon->querysql($getpo_sql) or die(mysql_error());
            return @$dbcon->getArray($result);
        }
    }
    $warehouse=new warehousemanageclass();
    print_r($warehouse->getPurchaseGoodsInfoFromPO()) ;
    ?>出现这个错误:PHP Fatal error:  Class 'storedbconclass' not found in /var/www/html/stock/storage/warehouse.manage.class.php on line 13楼上大哥麻烦再帮忙看看...多谢...多谢..
      

  3.   

    function getPurchaseGoodsInfoFromPO(){
            $dbcon=new dbconnect(constant("DB_USER"),constant("DB_PWD"), constant("DATABASE_STORE"), constant("DB_HOST"));  // 如果 这样调用 的话,你这个里面的 host.pass.database 都是要在getPurchaseGoodsInfoFromPO() 重新调用 的 getPurchaseGoodsInfoFromPO( host,passwd,database)
            $dbcon->connect();
            $dbcon->selectdb();
            //Create SQL  獲取PO單中所有物品的SQL語句如下:  $getpo_sql
            $getpo_sql="select * from ".constant("DATABASE_STORE").".".constant("TB_PURCHASELIST")." where state!=1 order by id desc";
            $result=$dbcon->querysql($getpo_sql) or die(mysql_error());
            return @$dbcon->getArray($result);
        }
      

  4.   

    那我extend 也是出现调用 dbconnect 这个类not found...楼上大哥一般都是怎么用的啊?教教我啊...多谢.
      

  5.   


    建议用 extends ,实现 起来方便!我也说了,如果用 extends 的话,要 在 dbconnect 里 实现 数据库 连接 和 selectdb
      

  6.   


    function __construct($db_user,$db_password,$db_name,$db_host="localhost"){
            $this->dbuser=$db_user;
            $this->dbpassword=$db_password;
            $this->dbname=$db_name;
            $this->dbhost=$db_host;
            $this->link=mysql_connect($this->dbhost,$this->dbuser,$this->dbpassword) or die("数据库连接发生错误,错误信息是:".mysql_error());
            mysql_select_db($this->dbname,$this->link);
            @mysql_query("SET NAMES 'UTF-8'");
        }
      

  7.   

    楼上大哥,不好意思,我还是没有明白你的意思..我是extends dbconnect.php啊..但是我在getPurcaseGoodsInfoFromPO这个function中怎么去引用数据库呢?也就是dbconnect的对象dbcon呢?以前我是用global一个dbcon能用,现在就不能用了..所以来向你请教哈.多谢你.class warehousemanageclass extends storedbconclass{
    /**
     *  @method __construct()
     *  @Description--構造方法,實例化類方法和變量.
     */
        function __construct(){
        }
    /**
     *  @method:  getPurchaseGoodsInfoFromPO()
     *  @Description :該函數方法是用來從采購單(PO)中獲取所有正在采購的物品
     *  @用來提示所有應入庫的物品.
     *  @global $dbcon
     *  @author Loo Zhong Chi
     */
        function getPurchaseGoodsInfoFromPO(){
            $storecon=new storedbconclass(constant("DB_USER"),constant("DB_PWD"), constant("DATABASE_STORE"), constant("DB_HOST"));
            //Create SQL  獲取PO單中所有物品的SQL語句如下:  $getpo_sql
            $getpo_sql="select * from ".constant("DATABASE_STORE").".".constant("TB_PURCHASELIST")." where state!=1 order by id desc";
            $result=$storecon->querysql($getpo_sql) or die(mysql_error());
            return @$storecon->getArray($result);
        }
    }
    $warehouse=new warehousemanageclass();这样还是提示那个db类找不到.
      

  8.   


    二个一起说,把你搞混了 ... 
    class warehousemanageclass{
    /**
     *  @method __construct()
     *  @Description--構造方法,實例化類方法和變量.
     */
        function __construct(){
        }
    /**
     *  @method:  getPurchaseGoodsInfoFromPO()
     *  @Description :該函數方法是用來從采購單(PO)中獲取所有正在采購的物品
     *  @用來提示所有應入庫的物品.
     *  @global $dbcon
     *  @author Loo Zhong Chi
     */
        function getPurchaseGoodsInfoFromPO( $user,$pass,$dababase,$host ){  // 注意这个地方,必成你相对就的,就好了
            $storecon=new storedbconclass($user,$pass, $database, $host);
            //Create SQL  獲取PO單中所有物品的SQL語句如下:  $getpo_sql
            $getpo_sql="select * from ".constant("DATABASE_STORE").".".constant("TB_PURCHASELIST")." where state!=1 order by id desc";
            $result=$storecon->querysql($getpo_sql) or die(mysql_error());
            return @$storecon->getArray($result);
        }
    }
    $warehouse=new warehousemanageclass();
      

  9.   

    上面一贴要加上 $storecon->connect();
    $storecon->selectdb();
    用 extends 就要把 dbconnect 改成 6楼然后 class warehousemanageclass extends dbconnect{
    /**
     *  @method __construct()
     *  @Description--構造方法,實例化類方法和變量.
     */
        function __construct(){
        }
    /**
     *  @method:  getPurchaseGoodsInfoFromPO()
     *  @Description :該函數方法是用來從采購單(PO)中獲取所有正在采購的物品
     *  @用來提示所有應入庫的物品.
     *  @global $dbcon
     *  @author Loo Zhong Chi
     */
        function getPurchaseGoodsInfoFromPO( ){  // 注意这个地方,必成你相对就的,就好了
            //Create SQL  獲取PO單中所有物品的SQL語句如下:  $getpo_sql
            $getpo_sql="select * from ".constant("DATABASE_STORE").".".constant("TB_PURCHASELIST")." where state!=1 order by id desc";
            $result=$this->querysql($getpo_sql) or die(mysql_error());
            return @$this->getArray($result);
        }
    }
    $warehouse=new warehousemanageclass();
      

  10.   

    我把数据库改成6楼的那个了.然后
    include_once("../db/store.dbcon.class.php");
    class warehousemanageclass extends dbconnect{  //这个地方就是14行.
    /**
     *  @method __construct()
     *  @Description--構造方法,實例化類方法和變量.
     */
        function __construct(){
        }
    /**
     *  @method:  getPurchaseGoodsInfoFromPO()
     *  @Description :該函數方法是用來從采購單(PO)中獲取所有正在采購的物品
     *  @用來提示所有應入庫的物品.
     *  @global $dbcon
     *  @author Loo Zhong Chi
     */
        function getPurchaseGoodsInfoFromPO( ){  // 注意这个地方,必成你相对就的,就好了
            //Create SQL  獲取PO單中所有物品的SQL語句如下:  $getpo_sql
            $getpo_sql="select * from ".constant("DATABASE_STORE").".".constant("TB_PURCHASELIST")." where state!=1 order by id desc";
            $result=$this->querysql($getpo_sql) or die(mysql_error());
            return @$this->getArray($result);
        }
    }
    $warehouse=new warehousemanageclass();还是出现 PHP Fatal error:  Class 'storedbconclass' not found in /var/www/html/stock/storage/warehouse.manage.class.php on line 14这个错误.