hjmsolar 发表于 2013-09-03 00:23

Fatal error: Call to undefined method stdClass……

本帖最后由 hjmsolar 于 2013-09-03 00:39 编辑


class clsDB {
    ……
   
    public function exec($pSQL = '') {
      if (!is_resource($this->Conn)) {
            $this->connect();
      }
      if (is_resource($this->Conn)) {
            if ($pSQL == '') {
                $this->Res = pg_query($this->Conn, $this->SQL);
            } else {
                $this->Res = pg_query($this->Conn, $pSQL);
            }
            return ($this->Res === false) ? false : true;
      } else {
            return false;
      }
    }
}

class clsSESSION {
        ……
    function read($pkey) {
      global $gDB;
      ……
      $gDB->exec('……');
      ……
      
    }
    function write($pkey, $pdata) {
      global $gDB;
      ……
      $gDB->exec('……');
      ……
    }
}

$gDB = new clsDB();
$gSession = new clsSESSION();
在$gSession::read()里面第一次运行$gDB->exec()没问题。
到在$gSession::write()里面第二次运行$gDB->exec()就出现“Fatal error: Call to undefined method stdClass::exec() in …path… on line xx ”的错误提示。
请教一下大家,这是怎么回事,如何解决。

hjmsolar 发表于 2013-09-03 10:34

本帖最后由 hjmsolar 于 2013-09-03 10:34 编辑

找到办法了,修改clsSESSION如下:class clsSESSION {
    private $db;
      ……
    function __construct() {
      global $gDB;
      $this->db = &$gDB;
      ……
    }
    function read($pkey) {
      ……
      $this->db->exec('……');
      ……
      
    }
    function write($pkey, $pdata) {
      ……
      $this->db->exec('……');
      ……
    }
}
原因不明,还请指教。

maochanglu 发表于 2013-09-03 13:03

难道是因为 global 了两次?
不明白。
页: [1]
查看完整版本: Fatal error: Call to undefined method stdClass……