Inheritance ......

liunx

Guest
Hi.
Sorry to disturb you again ;)
I'm taking my first steps in PHP5
I'd like to develop a few classes ( with inheritance )
to manage DML statements for my
user table.
I made this simple snippet:

<?php
error_reporting(E_STRICT);
require_once("classAbstractDatabase.php");
class User
{
private $_properties = array(
'username'=>null,
'password'=>null,
'email'=>null,
'uid'=>null
);
public function __construct(){}
public function _get($propertyName)
{
if(!array_key_exists($propertyName,$this->_properties))
{
throw new Excepetion('Invalid property value '.get_class($this));
}
if(method_exists($this,'get',$propertyName))
{
return call_user_func(array($this,'get',$propertyName));
}
else
{
return $this->_properties[$propertyName];
}
}
}//
class UserQueryBuilder extends User
{
private $_insert;
public function __construct()
{
parent::__construct();
}
protected function setInsert()
{
$this->_insert = "INSERT INTO user (user_id,user_name,user_password,user_email)
VALUES ('','{$this->username}','{$this->password}','{$this->email}');";
}
protected function getInsert()
{
return $this->_insert;
}
/*
Other queries
*/
}
class UserQueryLoader extends UserQueryBuilder
{
private $_db;
private $_lastInsertId;
public function __construct(AbstractDb $obj)
{
parent::__construct();
$this->_db = $obj;
}
public function loadInsert()
{
parent::setInsert();
$this->_db->performQuery(parent::getInsert());
$this->_lastInsertId = $this->_db->getInsertId();
}
public function getLastInsertId()
{
return $this->_lastInsertId;
}
/*
Other stuff
*/
}
$options=array('__host'=>'','__user'=>'','__password'=>'','__database'=>'');
$objDb = new AbstractDb($options);
$objLd = new UserQueryLoader($objDb);
$objLd->username = "whisher";
$objLd->password = "whisher";
$objLd->email = "[email protected]";
$objLd->loadInsert();
echo $objLd->getLastInsertId();

?>

Is there any mistake ?
What do you think about it ?

Take care.
Bye
 
Back
Top