Hi. I'm new at php oop, and I have a question.
I have this method in my class:
public function find($user = null) {
if ($user) {
$field = (is_numeric($user)) ? 'id' :'username';
$data = $this->_db->get('users', array($field, '=', $user));
if ($data->count()) {
$this->_data = $data->first();
return true;
}
}
return false;
}
When I call class function count() I got message:
Call to a member function count() on a non-object
And here is my DB class methods:
public function action($action, $table, $where = array()) {
if (count($where) === 3) {
$operators = array('=', '<', '>', '<=', '>=');
$field = $where[0];
$operator = $where[1];
$value = $where[2];
if (in_array($operator, $operators)) {
$sql = "{$action} FROM {$table} WHERE {field} {$operator} ?";
if (!$this->query($sql, array($value))->error()) {
return $this;
}
}
}
return false;
}
public function get($table, $where) {
return $this->action('SELECT *', $table, $where);
}
public function results() {
return $this->_results;
}
public function first() {
return $this->_results()[0];
}
public function error() {
return $this->_error;
}
public function count() {
return $this->_count;
}
What I have tried:
I understand that $data isn't an object:
var_dump($data); returns boolean false????