How can you use a class inside of another class? Consider the following.
class myClass
{
var $user_id;
var $username;
var $password;
var $something;
var $db; // i would like this to be the pear DB object...
// some functions here .... to set variables and so forth
// then I do something like this...
function getUserData(){
$data = $db->getOne("SELECT something FROM sometable WHERE username='$this->username'");
return $data;
}
} // end class
/// sql config and DB object included in a seperate file...
require_once( 'DB.php' );
$db = DB::connect( "mysql://$dbuser:$dbpass@$dbhost/$dbname" );
if (DB::isError($db)) {
die ($db->getMessage());
}
$db->setFetchMode(DB_FETCHMODE_OBJECT);
PEAR::setErrorHandling(PEAR_ERROR_DIE);
/// then... /// code here...
$mem = new myClass;
$mem->username = "someusername";
$mem->db = $db;
$mem->getUserData();
I get the old "Member function of non object" error. How can I use the $db object without extending pears DB.php?