【问题标题】:fatel error is coming in getRow() functiongetRow() 函数中出现致命错误
【发布时间】:2013-11-04 02:40:12
【问题描述】:

我正在使用这种方法从数据库中获取行并显示在 frontend 上,但是当它执行时它给出了一个致命的错误,即

致命错误:在第 432 行对 D:\xampp\htdocs\Deshbandhu\class\tblOp.php 中的非对象调用成员函数 getRow()

我正在使用的功能代码是

 function getRowFields($fields,$where = NULL, $order = NULL){
    global $db; 
    $fields = ($fields) ? " $fields "           : " * ";
    $where  = ($where) ? " WHERE $where "       : "";
    $order  = ($order) ? " ORDER BY $order "    : " ORDER BY {$this->primaryKey} ";
    $sql    = "SELECT $fields FROM {$this->table} $where $order;"; // limit 0,1
    $res    =$db ->getRow($sql, DB_FETCHMODE_ASSOC);
    echo $res; exit;
    if (DB::isError($res))
        return $this->raiseError($res);
    return $res;
}

getRow() 的定义是

function getRow($where = NULL, $order = NULL,$fields=NULL){
    global $db; 

   $sql    = $this->buildQuery(NULL, TBLOP_EXECUTE_SELECT, $where, $order,$fields);

    //echo $sql.'<br>';
    $res    = $db->getRow($sql, DB_FETCHMODE_ASSOC);

    if (DB::isError($res))
        return $this->raiseError($res);

    return $res;
}

这段代码在实时服务器上运行并且没有给出任何错误,但是当我在本地服务器上执行它时,它会显示这样的错误。

【问题讨论】:

    标签: php mysql cakephp pear


    【解决方案1】:

    问题在于您的 $db 变量,检查您的 DB 初始化代码,它可能无法连接到数据库并且没有检查错误。

    【讨论】:

      【解决方案2】:

      对我来说看起来像 AdoDB,我使用的是相同的。您忘记了数据库设置吗?看起来应该是这样的:

      $db = ADONewConnection("mysql"); // eg 'mysql' or 'postgres'
      $db->Connect("host", "user", "password", "table");
      

      【讨论】:

      • 我正在使用这个$dsn = "mysql://".DB_USER.":".DB_PASS."@".DB_HOST."/".DB_DATABASE;
      • 您声明了 $dsn,但作为代码中的对象,您使用了 $db。我什至不确定你的声明是否像它应该的那样工作。
      【解决方案3】:

      我之前遇到过这个问题,我通过修复我的表来解决它。

      【讨论】:

        猜你喜欢
        • 2014-09-20
        • 2017-05-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-02-16
        • 1970-01-01
        相关资源
        最近更新 更多