Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/227.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
理解php成员系统中的一个错误_Php_Mysql_Fatal Error - Fatal编程技术网

理解php成员系统中的一个错误

理解php成员系统中的一个错误,php,mysql,fatal-error,Php,Mysql,Fatal Error,我正在使用会话、函数和MySQL查询在php中构建一个成员系统, 我遇到了一个问题或错误,我不理解其含义以及如何纠正它。 在这件事上的任何帮助都将不胜感激 错误读取 Fatal error: Call to a member function error() on a non-object in /home/ob219/public_html/membership/index.php on line 6 $user = DB::getInstance()->get('users', ar

我正在使用会话、函数和MySQL查询在php中构建一个成员系统, 我遇到了一个问题或错误,我不理解其含义以及如何纠正它。 在这件事上的任何帮助都将不胜感激

错误读取

Fatal error: Call to a member function error() on a non-object in /home/ob219/public_html/membership/index.php on line 6
$user = DB::getInstance()->get('users', array('username', '=', 'ben'));

if($user->error()) {
    echo 'No user';
} else {
    echo 'OK!';
}
索引代码
$user = DB::getInstance()->get('users', array('username', '=', 'ben'));

if($user->error()) {
    echo 'No user';
} else {
    echo 'OK!';
}
db.php函数

$user = DB::getInstance()->get('users', array('username', '=', 'ben'));

if($user->error()) {
    echo 'No user';
} else {
    echo 'OK!';
}
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 delete($table, $where) {
    return $this->action('DELETE', $table, $where);

}

public function error() {
    return $this->_error;
}
    <?php
require_once 'core/init.php';
$user = DB::getInstance()->get('Users', array('username', '=', 'ben'));
if((!$user->count())) {
    echo 'No user';
} else {
    echo 'OK!';
}
公共函数操作($action,$table,$where=array()){
如果(计数($where)==3){

$operators=array(“=”、“>”、“=”、“是一个简单的错误,我把用户作为表名,在index.php中我有用户

解决方案

$user = DB::getInstance()->get('users', array('username', '=', 'ben'));

if($user->error()) {
    echo 'No user';
} else {
    echo 'OK!';
}
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 delete($table, $where) {
    return $this->action('DELETE', $table, $where);

}

public function error() {
    return $this->_error;
}
    <?php
require_once 'core/init.php';
$user = DB::getInstance()->get('Users', array('username', '=', 'ben'));
if((!$user->count())) {
    echo 'No user';
} else {
    echo 'OK!';
}

错误基本上是告诉你
$user
不是一个对象。它可以是
null
false
等等。它意味着
$user
false
null
。这不是一个对象,它没有
error
函数。你的
get()
函数(调用
action()
)返回了
false
NULL
。很可能您的查询失败,并且您的
返回$this
从未被调用。@Rocket Hazmat谢谢您,我将重新检查我的查询,然后再次检查