0

错误:

致命错误:在第 61 行的 paging.php 中的非对象上调用成员函数 fetchAll()

编码:

$this->_results = $this->_db->getOrder('users', array('first_name', 'ASC')); 

    while ($row = $this->_results->fetchAll(PDO::FETCH_ASSOC) ) { //Line 61 Error

函数(getOrder()用于按顺序获取数据):

public function getOrder($table, $order) {  
   return $this->actionOrder('SELECT *', $table, $order);
}


public function actionOrder($action, $table, $order = array()) {

if (count($order) === 2) {
        $operators = array('ACS','DESC');

        $field    = $order[0];
        $operator = $order[1];

        if (in_array($operator, $operators)) {
            $sql = "{$action} FROM {$table} ORDER BY {$field} {$operator}";

            if (!$this->query($sql, array($operator))->error()) {
                return $this;
            }
        }
    }
}

我要完成的工作:生成/打印/回显已在数据库中注册的用户列表。

我试过的:

  • 使用foreach而不是while

  • 检查我与数据库的连接(检查正常)

  • 将使用的变量从类级别私有变量 ( $this->_blahblahblah) 更改为仅局部范围变量$blahblahblah

  • 使用各种形式的fetchAll

  • 检查_results对象的值

  • 休息后我尝试了这个:

    公共功能 people_display() {

    $output = '';
    
    //$this->_results = $this->_db->getOrder('users', array('first_name', 'ASC'));
    $results = $this->_db->get('users', array('username', '=', $this->_user = User::data()->username));
    
    while ($row = $results->fetchAll(PDO::FETCH_ASSOC) ) {
    
        $output .= '
        <tr>
            <td>' . $row['username']. '</td>
            <td>' . $row['first_name']. '</td>
            <td>' . $row['last_name']. '</td>   
        </tr>';
            //<td>'/* . . */'</td> 
            //<td>'/* . . */'</td>
    
    }
    

这给了我错误:

致命错误:无法访问第 152 行 user.php 中的私有属性 Paging::$_data

有人可以帮帮我吗?先感谢您

4

0 回答 0