We can create csv files using perl script. It should be as follows.
my $table=$q->param('table');
my $field_name=defined($q->param('column'))?$q->param('column'):"*";
my $file_name="Report".time();
my $sql_rep = 'SELECT '.$field_name.' FROM '.$table;
$file = "$file_name.csv";
my $getkey = $dbh->prepare($sql_rep);
$getkey->execute;
my (@names, @values);
my $xi=0;
my $xii=0;
my @datas;
while( my @row = $getkey->fetchrow_array ) {
$xii=0;
foreach my $data (@row) {
push @{$datas[$xi]}, $data;
$xii++;
}
$xi++;
}
$getkey->finish;
open my $OUT, '>', "report_generator/".$file or die $!;
for(my $yi=0;$yi<$xi;$yi++) {
@values=();
for(my $yii=0;$yii<$xii;$yii++) {
$datas[$yi][$yii] =~ s/"/""/g;
push @values, qq{"$datas[$yi][$yii]"};
}
print {$OUT} (join ",", @values) . "\n";
}
close $OUT;