I have a class that holds a mysqli instance (this to avoid spreading database settings all over the source code).
The class DB looks like:
class DB {
private $mysqli;
public function connect() {
$this->mysqli = new mysqli("localhost", "user", "pwd", "db-name");
}
public function __call($method, $args) {
return $this->mysqli->$method(extract($args));
}
}
As you might see what I'm trying to do is to overload every method call executing the mysqli ones.
In the other php file I have:
$unq_vstr = $this->db->query("SELECT * FROM user_log WHERE user_ip='$ip' AND user_last_visit='$now';");
if ($unq_vstr->num_rows > 0) { // ERROR
// ...
}
But I'm getting "Notice: Trying to get property of non-object in /home/alessandro/www/admin/index.php on line 25" corresponding to the if statement ($unq_vstr->num_rows).
What am I doing wrong? I'm pretty sure it might depend on the DB class, but I can't figure out what the problem is.
Do you think I should use an alternative way to do it (without wrap mysqli inside my own class)? Any suggestion is appreciated.