PHP编程致命错误在我的代码中

时间:2014-02-16 16:07:02

标签: php mysql cakephp-helper

错误:

  

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

守则:

$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>
    
    }
    

这给了我错误:

  

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

有人可以帮帮我吗? 提前谢谢

0 个答案:

没有答案
相关问题