Chaos Chaos - 6 months ago 70
MySQL Question

Codeigniter: Changing SQL query in model leads to a "failed to open stream" warning. Testing with a simple select * query works, however

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?

Answer

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).