Ok I have a problem which i assume is not that complicated,
but it is for me...
I have a class called Display that makes calls to a database access class called DAO
where all the SQL code is and the logic for fetching the data.
I've always been instantiating this class for every function, (like this)
require_once(classname)
$DAO = new DAO();
which is not very good. so now i want to figure out a way to just do it once
in the beginning of the class and then access is whenever i want to
i've played around with constructors, autoload and global variables without getting the result i want.
what can i do?
here is a snippet of the class i currently use,
it works fine for fetching single row data but multiple records i will need to access the FetchArray class from the DAO
which fetches the mysql array.
any comments are greatly appreciated
class Display {
function getDBArray($function, $id) {
$getArray = call_user_func(array($DAO, $function), $id);
$return = $DAO->fetchArray($getArray);
return $return;
}
function postDBArray($function, $values) {
$postArray = call_user_func(array($DAO, $function), $values);
}
function getUserInfo($id){
$user = $this->getDBArray('getUserInfo', $id);
echo hello $user['name'] ;
}
}