accessing a class from within a class
how do I access a class from within a class?
I'll give an example that wont work, but it's what I want to do
PHP Code:
class db{
function connect(){
//connect to db
}
function query(){ //query }
...
}
$Db = new db();
$Db->connect();
class wut{
function whatever(){
$Db->query($sql);
}}
$woot = new wut();
$woot->wut();
I've not tried it, but could I use db::query($sql) in the second class?
but, wouldn't I have to connect to the database via db::connect again since it's static or w/e?
edit
would doing something like
PHP Code:
//in class two
var $h;
$h->query($sql);
//instead of just $woot->wut();
$woot->h = $Db;
$woot->wut();
work?
my schools blocked my host, so I can't find out :(