Welcome Guest, Not a member yet? Register   Sign In
Fatal error: Call to undefined method CI
#1

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
Reply
#2

Have you loaded the database libary in the controller. Or even autoload it in the config file?
On the package it said needs Windows 7 or better. So I installed Linux.
Reply
#3

(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)
Reply
#4

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.
Reply
#5

(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
Reply
#6

Maybe you intended to use the function csv_from_result().

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




Theme © iAndrew 2016 - Forum software by © MyBB