Welcome Guest, Not a member yet? Register   Sign In
dbutil->csv_from_result() produces only header record.
#1

When I tried to create a CSV file using dbutil->csv_from_result() CI3 gave me just a header record missing whole actual data rows.
I found something after I played around with system/database/DB_utility.php.
The original code is (CI3.1.7 is the same) like this;

PHP Code:
// Next blast through the result array and build out the rows
while ($row $query->unbuffered_row('array'))
{
    
$line = array();
    foreach (
$row as $item)
    {
        
$line[] = $enclosure.str_replace($enclosure$enclosure.$enclosure$item).$enclosure;
    }
    
$out .= implode($delim$line).$newline;


In my environment (CI3 and PostgreSQL 10), there was no unbuffered_row in the query object, so the try misses.
I remember CI2's dbutil->csv_from_result() worked fine with PostgreSQL 9.2 and the code in the both programs look the same...

Then I gave a modification to the original code as follows and it works fine for me.

PHP Code:
//while ($row = $query->unbuffered_row('array'))  // Original : while iteration doesn't work with object
foreach ($query->result_array() as $row)
{
    
$line = array();
    foreach (
$row as $item)
    {
 
              $line[] = $enclosure.str_replace($enclosure$enclosure.$enclosure$item).$enclosure;
    }
    
$out .= implode($delim$line).$newline;


I'm not exactly sure if it works for everyone, but I believe it will help someone who have the same issue as I had.
Reply
#2

(This post was last modified: 09-10-2018, 05:43 AM by php_rocs.)

@yoshee,

If you feel that this is a real issue then I suggest that you put in a pull request so that others will not run into this issue https://github.com/bcit-ci/CodeIgniter
Reply




Theme © iAndrew 2016 - Forum software by © MyBB