Hi anyOne.
I'm learning OOP and I'd like
to know if this is the right way
to implement a class hierarchy:
config (name table,Db and the connection parameters)
prepareQuery(you can image it 🙂 )
abstract Database library
executeQuery(as above !)
dosomething.
Here a snippet of code:
<?php
class Config {
var $tableName = array();
function Config()
{
$this->tableName['user']['table'] = "users";
$this->tableName['user']['id'] = "user_id";
$this->tableName['user']['name'] = "username";
$this->tableName['user']['password'] = "password";
$this->tableName['user']['confirm'] = "confirm";
$this->tableName['sessions']['table'] = "sessions";
$this->tableName['sessions']['user_id'] = "user_id";
$this->tableName['sessions']['time'] = "time";
$this->tableName['sessions']['uid'] = "userCookieUid";
$this->tableName['privilege']['table'] = "_privilege";
$this->tableName['privilege']['priv_id'] = "priv_id";
$this->tableName['privilege']['priv_type'] = "priv_type";
$this->tableName['task']['table'] = "task";
$this->tableName['task']['user_id'] = "user_id";
$this->tableName['task']['priv_id'] = "priv_id";
}
}//
class prepareQuery extends Config
{
var $query = array();
function prepareQuery()
{
parent::Config();// IS IT A RIGHT WAY ?
}
function insertUser($username,$password)
{
$password = md5($password);
$this->query['insertUser'] = "INSERT INTO
{$this->tableName['user']['table']}
({$this->tableName['user']['name']},{$this->tableName['user']['password']})
VALUES ('".$username."','".$password."')";
}
function getQuery($queryName)
{
return $this->query[$queryName];
}
}//
$obj = new prepareQuery();
$obj->insertUser("user","password");
echo $obj->getQuery("insertUser");
?>
I'm waiting in trepidation for your news 😃
Take care.