Forum Moderators: coopster
$db = new db;
$results = $db->fetch_results("select * from table");
etc.
I want to make a class called records.
<?
class Records {
function latestRecords() {
return $db->get_results("select * from records order by id desc limit 0,10");
} // End latestRecords()
}
?>
My question is about using the $db object inside a class. I.e. the class uses $db, as well as the script outside the class using $db.
For an ordinary function I use "global $db" which works fine, but what's the best way to do this for a class?
Up to you ;)
You can either call the original class in the second like: $db=new db; (require() the original class first)
Or, you can use the Extends Keyword [php.net]
HTH
Nick
And regards to the second answer, Neither class extends the other, they are both completely seperate, except one uses the other.
I guess my question really is how do I access an Object that already exists outside the class, from inside a class.