Access parent property from child

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



dear all ...

i have question, i've tried look at google but still can't figured out
how to do it...
i want access parent property from child object the code was like

<?

class DAO
{
    private $db;
    private $id;

    protected function getId()
    {
        return $this->id;
    }
    protected function setId($id)
    {
        $this->id   = $id;
    }

    function getDB()
    {
        return $this->$db;
    }
    function setDB($db)
    {
        $this->db   = $db;
    }

    public function load($id)
    {
        $query  = "SELECT * FROM ".
                            constant(get_class($this)."::tableName").
                            " WHERE ".
                            constant(get_class($this)."::pkFields").
                            "='".$id."'";
        $rs     = $this->db->Execute($query);
        $cObj   = $rs->FetchObject(true);

        return $cObj;
    }

    public function save($rowData)
    {
        $this->db->debug = true;
        $query      ="Select * FROM
".constant(get_class($this)."::tableName")."\n";
        $res        =$this->db->Execute($query);
        $insertSQL  = $this->db->GetInsertSQL($res,$rowData);
        $res        =$this->db->Execute($insertSQL);
        if($res)
            return true;

        return false;
    }

    public function update($row, $id)
    {
        $query      =   "SELECT * FROM
".constant(get_class($this)."::tableName")."\n"
                    .   "WHERE
".constant(get_class($this)."::pkFields")."='".$id."'";
        $res        = $this->db->Execute($query);
        $updateSQL  = $this->db->GetUpdateSQL($res,$row);
        $db->Execute($updateSQL);
    }

    public function getAll($criteria='', $order='')
    {
        if(empty($order))
            $order  = constant(get_class($this)."::pkFields");

        $query      = "SELECT * FROM
".constant(get_class($this)."::tableName")."\n"
                    . $criteria
                    . "ORDER BY ".$order;
        $row        =   $this->db->Execute($query);
        if(!$row)
        {
            $this->error    = $this->db->ErrorMsg();
            return      false;
        }
        return $row->getArray();
    }

}

and i have this child
<?php

include 'BaseDAO.class.php';
class TaskCLDAO extends DAO
{
    const tableName = 'task';
    const pkFields  = 'task_id';

    function findWithRelation($id)
    {
          $query = "select * from task LEFT JOIN log ON task.id=log.task_id";
          $db      =  parent::getDB();
          $res     =  $db->Execute($query);
          return $res->getArray();
    }
}


?>

and this is the class that called it

<?php

$obj   = new TaskCLDAO();
$obj->setDB($db); //  i have another file called config that initialized the db;
$res   = $obj->findWithRelation(1);

?>

but the php's said

Fatal error: Cannot access empty property...

what does it mean ?? is there another way to access "$db" that parent have ?

TIA
-- 
Jangan tanyakan apa yang Indonesia telah berikan pada mu
tapi bertanyalah apa yang telah engkau berikan kepada Indonesia

-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GU/IT  d- s: a-- C++ UL P L++ E W++ N* o-- K-
w PS  Y-- PGP- t++ 5 X R++ tv  b+ DI D+ G e+ h* r- z?
 ------END GEEK CODE BLOCK------

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux