hey I'm having a problem with a bit of code, it's long so I shortened it to the problem area.
Code:
class my_class extends Connect {
var $connection;
function set_conn() {
//this creates a connection and works as tested by another script
$this->connection = new Connect();
}
function get_conn() {
return $this->connection();
}
function get_data( $query ) {
if(!isset($this->connection)) {
print "Error connecting to the database";
} else {
$i = 0;
$get = $this->connection->Query($query);
while($data = $this->connection->FetchArray($get)) {
$result[$i++] = $data;
}
}
return $result;
}
}
Then I have on my main script the following :
Code:
$config = new my_class();
$config->set_conn();
$functions = new my_class2();
$functions->grab('','','');//this is all ok
then I have another class that extends that class
Code:
class my_class2 extends my_class {
function grab($type, $limit='10', $cat='1') {
switch($type) {
case 'most_viewed_home':
$q = "some query";
my_class::get_data($q); //or $this->get_data(q);?
break;
}
}
the problem is, for some reason $connection is no longer set when I use the grab function. all I get is Error connecting to the database. I'm sure I'm missing something silly, however I can't work it out. Can anybody see the problem?
|