mysql - fatal error : Call to a member function result() on a non-object in code igniter model working fine in localhost

标签 mysql codeigniter fatal-error

这是我的模型代码:

function get_ads($page=0, $type, $limit=1, $order=' order by rand()') { 
    if ($page === 0) {
        $page = $this->get_adpage(); 
        $qry = "select * from tbl_ads ";
        $qry .= " where status=1 and pages like '%".$page. "%'";
        $qry .= " and type = ".intval($type);
        $qry .= $order;
        $qry .= intval($limit) > 1 ? " limit 0,".$limit : " limit 0,1";   
        $results = $this->db->query($qry)->result(); return $results;}
     }
}

这样查询

SELECT * FROM tbl_ads WHERE STATUS=1 AND pages LIKE '%1%' AND TYPE = 1 ORDER BY RAND() LIMIT 0,1` 

Controller 代码是

function get_ads(){
    $this->main_model->get_ads(14,2,1);
}

上传到服务器时,它在本地工作正常,有时显示 fatal error ,但有时工作正常。

感谢您的帮助

最佳答案

解决办法在这里 $this->db->query($qry)->result() 代替 result() 多行的 result_array() 或单行结果的 row_array() 做到了这一点

关于mysql - fatal error : Call to a member function result() on a non-object in code igniter model working fine in localhost,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29936361/

相关文章:

mysql - 连接两个表两次并返回重复的列名

python - 如何停止致命的Python错误: PyEval_SaveThread: NULL tstate

MySQL Union 总是返回一行包含 NULL 的数据

mysql - 如何在 Firebird 中进行多选查询

mysql - 将日期从文件传递到 mysql 的 Shell 脚本

php - Laravel 中间表

codeigniter - 在 Codeigniter 下,是否可以看到 mysql_error()?

javascript - MySQL数据显示不同价格JavaScript

python - 致命的 python 错误 : (pygame parachute) Segmentation Fault

ios - 当我尝试从不同的 View 更改标签文本时,我不断收到此错误