Possible Duplicate:
Reference - What does this error mean in PHP?
I have two classes:
- Database Class
- Libtables Class
In the Database Class I've created an object to work with mysqli for the entire script. It works when I'm trying to call a function from the Database Class in a .php file.
Simplified Database Class:
class Database {
protected static $_instance;
protected $_mysqli;
protected $_query;
public function __construct($host, $username, $password, $db) {
$this->_mysqli = new mysqli($host, $username, $password, $db)
or die("There was a problem connecting to the database");
}
public function close() {
$this->_mysqli->close();
}
public function query($q) {
return $this->_mysqli->query($q);
}
}
But when I'm trying to call a function from the Database Class in the Libtables Class it fails and I get an error called: "Call to a member function query() on a non-object"
Simplified Libtables Class:
class Libtables {
function getCol($table) {
$q = "SELECT * from " . $table . ";";
$res = $db->query($q);
return $res;
}
}
I've created a Database Class Object this way:
$db = new Database(DB_HOST, DB_USER, DB_PASS, DB_NAME);
global $db;