DB Util csv_from_result() question - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: DB Util csv_from_result() question (/showthread.php?tid=18639) Pages:
1
2
|
DB Util csv_from_result() question - El Forum - 05-13-2009 [eluser]i_am_using_ci[/eluser] Hi, I am trying to generate csv from result of my db select query... My code (as in manual): Code: $this->load->dbutil(); I am getting error: "You must submit a valid result object"... I am submitting valid result object as $query and my result set has about 40 rows... I've tried to understand wtf and opened DB_utility.php CI class source, there are: Code: function csv_from_result($query, $delim = ",", $newline = "\n", $enclosure = '"') { but my query result object doesn't have 'field_names' method... What I am doing wrong? DB Util csv_from_result() question - El Forum - 05-13-2009 [eluser]Dam1an[/eluser] To get the result object you need to do Code: $result = $query->result(); DB Util csv_from_result() question - El Forum - 05-13-2009 [eluser]i_am_using_ci[/eluser] Okay, but it's not like in manual firstly... Secondly - I got result object, but error is same - there is no 'field_names' method... DB Util csv_from_result() question - El Forum - 05-13-2009 [eluser]Evil Wizard[/eluser] the result object is an array of all your results. The csv_from_result() method extracts the field names from the result set to set the CSV header line and then iterates through the results. The method returns a string containing the result in csv format, this method does not write the csv file. DB Util csv_from_result() question - El Forum - 05-13-2009 [eluser]i_am_using_ci[/eluser] And? I have result, but can't pass csv_from_result() method check (method_exists()): Code: if ( ! is_object($query) OR ! method_exists($query, 'field_names')) DB Util csv_from_result() question - El Forum - 05-13-2009 [eluser]Evil Wizard[/eluser] you could try a var_dump() of the result object, but php also has an fputcsv method that adds the line to the csv file and writes it, but it is (PHP 5 >= 5.1.0) DB Util csv_from_result() question - El Forum - 05-13-2009 [eluser]i_am_using_ci[/eluser] I need to do it with CI, and understand why it doesn't work.. DB Util csv_from_result() question - El Forum - 05-13-2009 [eluser]Evil Wizard[/eluser] ok, just post the result of the var_dump($query->result()); and we'll try and help solve this with you ;o) DB Util csv_from_result() question - El Forum - 05-13-2009 [eluser]i_am_using_ci[/eluser] array 0 => object(stdClass)[21] public 'id' => string '1' public 'data' => string 'aaa' 1 => object(stdClass)[22] public 'id' => string '2' public 'data' => string 'bbb' DB Util csv_from_result() question - El Forum - 05-13-2009 [eluser]Evil Wizard[/eluser] is that the result from the db object via ... Code: $this->load->dbutil(); |