$this->data = $this->dbh->getRow($query, array($user),DB_FETCHMODE_ASSOC);
 $this->dbh->getRow第一个 -> 是调用属性 dbh但是第二个 -> 会什么怎么回事呢。。

解决方案 »

  1.   


     精心研读下面代码将有助于你理解什么是属性重载。<?php
     //装入PEAR的 <a href="http://pear.php.net/package/DB/">DB package</a> //远程引用
     require_once "DB.php";  //特殊调用。
     class Persistable {                                   //类持续 贮存。类。。
      private $data = array();   
      private $table = "users";
      public function __construct($user)  //。方法 1  __construct{  $this->dbh = DB::Connect("mysql://user:password@localhost/database");// 属性 dbh,返回 resource .
       
    $query = "SELECT id, name, email, country FROM " .$this->table . " WHERE name = ?";//id,name,email,country //-----table users-----name = ?$this->data = $this->dbh->getRow($query, array($user),DB_FETCHMODE_ASSOC); //属性 data  getRow  
      
    }
      public function __get($member) { //。方法 2 __get
       if (isset($this->data[$member])) {
        return $this->data[$member];
       }
      }
      public function __set($member, $value) { //。。方法3 __set
       // dataset的ID是只读的
       if ($member == "id") {
        return;
       }
       if (isset($this->data[$member])) {
        $this->data[$member] = $value;
       }
      }
      public function __destruct() { //。。方法 4 __destruct
       $query = "UPDATE " . $this->table . " SET name = ?, 
       email = ?, country = ? WHERE id = ?";
       $this->dbh->query($query, $this->name, $this->email, 
       $this->country, $this->id);
      }
     }
     $class = new Persistable("Martin Jansen"); //建立对象。。
     $class->name = "John Doe";//
     $class->country = "United States";
     $class->email = "[email protected]";
    ?>