的index.php意外的PHP錯誤:調用一個成員函數......一個非對象
$user = db::getInstance()->get('test', array('user_name', '=', 'rahul'));
if ($user->count()){
echo 'NO user';
} else {
echo 'Ok';
}
db.php中
public function query($sql, $params = array()){
$this->_error = False;
if($this->_query = $this->_pdo->prepare($sql)){
$x =1;
if(count($params)) {
foreach ($params as $param) {
$this->_query->bindValue($x, $param);
$x++;
}
}
if($this->_query->execute()) {
$this->_results = $this->_query->fetchAll(PDO::FETCH_OBJ);
$this->_count = $this->_query->rowCount();
} else {
$this->_error = true;
}
}
return $this;
}
private function action($action, $table, $where){
if(count($where==3)) {
$opertors = array('=', '<', '>', '>=', '<=');
$field = $where[0];
$opertor = $where[1];
$value = $where[2];
if(in_array($opertor, $opertors)){
$sql = "{$action} FROM {$table} WHERE {$field} {$opertor} ?";
if (!$this->query($sql, array($value))->error()){
echo ' Go it';
return $this ;
}
}
}
return false;
}
public function get($table, $where){
return $this->action('SELECT *', $table, $where);
}
public function error(){
return $this->_error;
}
public function count(){
return $this->_count;
}
我得到這個錯誤:
Fatal error: Call to a member function count() on a non-object in C:\wamp\www\ooplr\index.php on line 10
我錯過了什麼?
嘗試轉儲$ user,看看裏面有什麼 – Matheno 2014-12-03 11:58:25
'var_dump($ user)'give ...? – 2014-12-03 11:58:38
它給'布爾假'....... – 2014-12-03 12:00:32