Forum Moderators: coopster
i have a database class for querying the db, and a counter class who should also be able to query the db.
if i use the counter class it should create a db object
like this:
class counter {
var $db; function counter() {
$this->db = new CDatabase;
}
function a_query_function() {
$this->db->query("some SQL");
}
}
but the command
$this->db->query("some SQL");
doesn't work because of pointing, c syntax like
($this->db)->query("some SQL");
doesn't work too,
what is the cleanest solution?
class Counter extends [us4.php.net] Db
{
define Counter class here
}
$counter = new Counter();
$counter->query("SELECT blah blah blah");
Another way
class Counter
$var db;
function Counter(&$db)
{
$this->db = $db;
}
}
$db = new Db();
$ctr = new Counter($db);
$ctr->db->query("SELECT blah blah blah");