I have this class:
class template {
private $_db;
public function __construct(){
$this->_db = \MysqliDb::getInstance();
}
public function get(){
return $this->_db->rawQuery("SHOW COLUMNS FROM rank LIKE 'view_template'");
}
}
But, when I execute the method get
, I get this error message:
Fatal error: Call to a member function rawQuery() on a non-object in {dir/to/my/file} on line 50
Line 50 is return $this->_db->rawQuery("SHOW COLUMNS FROM rank LIKE 'view_template'");
The weird thing is that it works fine if I move the code from __construct
to the get
method, like this:
class template {
private $_db;
public function get(){
$this->_db = \MysqliDb::getInstance();
return $this->_db->rawQuery("SHOW COLUMNS FROM rank LIKE 'view_template'");
}
}
What can be wrong in this case?