CodeIgniter Forums
Fatal error: Call to undefined method CI - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Fatal error: Call to undefined method CI (/showthread.php?tid=68938)



Fatal error: Call to undefined method CI - stckitbr - 09-15-2017

Hi guys, I'm having this problem when trying to generate an excel file with the data that is displayed on the screen. Clicking will show this error.

Fatal error: Call to undefined method CI_DB_mysql_utility::csv_from_array() in C:\wamp64\www\application\controllers\fluxo_caixa.php on line 259

help?  Huh


RE: Fatal error: Call to undefined method CI - rtenny - 09-15-2017

Have you loaded the database libary in the controller. Or even autoload it in the config file?


RE: Fatal error: Call to undefined method CI - Narf - 09-15-2017

(09-15-2017, 06:39 AM)stckitbr Wrote: Hi guys, I'm having this problem when trying to generate an excel file with the data that is displayed on the screen. Clicking will show this error.

Fatal error: Call to undefined method CI_DB_mysql_utility::csv_from_array() in C:\wamp64\www\application\controllers\fluxo_caixa.php on line 259

help?  Huh

csv_from_array() has never existed in CodeIgniter. I don't know where you got that from.

(09-15-2017, 07:47 AM)rtenny Wrote: Have you loaded the database libary in the controller. Or even autoload it in the config file?

He did, plus the extras (otherwise the error wouldn't mention CI_DB_mysql_utility)


RE: Fatal error: Call to undefined method CI - stckitbr - 09-15-2017

This application is from a friend of mine, I am giving a support for it. So it is not possible to do the procedure using csv from array? What would be the right way to do the procedure? When clicking you should download the excel file with the data that was displayed on the previous screen.


RE: Fatal error: Call to undefined method CI - ciadvantage - 09-16-2017

(09-15-2017, 06:39 AM)stckitbr Wrote: Hi guys, I'm having this problem when trying to generate an excel file with the data that is displayed on the screen. Clicking will show this error.

Fatal error: Call to undefined method CI_DB_mysql_utility::csv_from_array() in C:\wamp64\www\application\controllers\fluxo_caixa.php on line 259

help?  Huh

Try this 
Code:
$query_str="whatever your sql query maybe";
$query=$this->db->query($query_str);
$result_array = $query->result_array();
$fp = fopen('file.csv', 'w');

foreach ($result_array as $rs) {
   fputcsv($fp, $rs);
}

fclose($fp);

The snippet will get your result array and write to csv file.  Just make sure you set correct permission on 'file.csv'.  Also on query_str
if you need to pass on param within the sql statement then you need to use $this->db->escape($param), e.t.c

You can use active record method as per doc it will auto escape the param for you , how you want to write it is up to you

Regards


RE: Fatal error: Call to undefined method CI - Gustavo Martins - 09-19-2017

Maybe you intended to use the function csv_from_result().

You could combine this with the file helper to write the file.