douwei9973 2016-05-29 08:17
浏览 37
已采纳

Codeigniter:在模型中更改SQL查询会导致“无法打开流”警告。 但是,使用简单的select *查询进行测试

Database: MySQL version 5.6 hosted on remote server
Codeigniter version: 3.0.6 on localhost
PHP version: 5.5.9

I am working with a model, trying to build up a specific query and pass the result to my controller. Here's what they look like:

Model 1 (this works):

public function view_offer(){
    $sql = "SELECT Offer.OfferID, Outlet.OutletName, Offer.MaxSurge, Offer.OfferSurge, Offer.OfferStart, Offer.OfferStop, Offer.OfferQuantity, Offer.OfferSold, Offer.OfferStatus
            FROM OfferDetails Offer
            LEFT JOIN RestaurantOutlet Outlet 
            ON Offer.OutletID = Outlet.OutletID";
    //$query = $this->db->query('sql');
    $query = $this->db->get('OfferDetails');
    return $query->result_array();
}

Model 2 (This doesn't work):

public function view_offer(){
    $sql = "SELECT Offer.OfferID, Outlet.OutletName, Offer.MaxSurge, Offer.OfferSurge, Offer.OfferStart, Offer.OfferStop, Offer.OfferQuantity, Offer.OfferSold, Offer.OfferStatus
            FROM OfferDetails Offer
            LEFT JOIN RestaurantOutlet Outlet 
            ON Offer.OutletID = Outlet.OutletID";
    $query = $this->db->query('sql');
    //$query = $this->db->get('OfferDetails');
    return $query->result_array();  
}

Controller (This doesn't change while changing model):

public function running_offers(){
    print_r($this->offers->view_offer());
}

The difference between the 2 models is that one is a simple "SELECT * FROM OfferDetails;" while the other involves a table join and selected return of columns (check the commented out lines in each code segment).

For model 1, things go smoothly. I am able to query the database and print_r puts the array contents on screen.

Model 2 does not work. The warning that I get for model 2 is quite bizarre:

Warning: include(/var/www/html/admin/application/views/errors/html/error_php.php): failed to open stream: No such file or directory in /var/www/html/admin/system/core/Exceptions.php on line 269

Warning: include(): Failed opening '/var/www/html/admin/application/views/errors/html/error_php.php' for inclusion (include_path='.:/usr/share/php:/usr/share/pear') in /var/www/html/admin/system/core/Exceptions.php on line 269

Warning: include(/var/www/html/admin/application/views/errors/html/error_php.php): failed to open stream: No such file or directory in /var/www/html/admin/system/core/Exceptions.php on line 269

Warning: include(): Failed opening '/var/www/html/admin/application/views/errors/html/error_php.php' for inclusion (include_path='.:/usr/share/php:/usr/share/pear') in /var/www/html/admin/system/core/Exceptions.php on line 269

My localhost is an ubuntu machine. To simplify matters related to permissions, I have done the following:

chown -R my-user-id:www-data /var/www/html
chmod -R 777 /var/www/html

Googling the warning messages returned, I find references to change my php.ini file. Why? How can changing the query that will anyway get run in MySQL need me to change my php.ini file?

  • 写回答

1条回答 默认 最新

  • dszm02606009 2016-05-29 08:21
    关注

    Try:

    $query = $this->db->query($sql);
    

    failed to open stream error showed, because not available files, which used for showing error messages (error_php.php).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)