Hi,
Im just getting started with PHP, and I need to export a table from my sqlite database to a CSV or ideally XLS. I have found an example using mysql, but i cant convert it to work with sqlite.
Here is what i have so far:
<?php
$db = new PDO('sqlite:../ccm.sqlite');
$query = $db->query('SELECT * FROM Emails');
$export = sqlite_query ($query);
$fields = sqlite_num_fields ( $export );
for ( $i = 0; $i < $fields; $i++ ){
$header .= sqlite_field_name( $export , $i ) . "\t";
}
while( $row = sqlite_fetch_row( $export ) ){
//sqlite_fetch_row doesnt actually exist...
$line = '';
foreach( $row as $value ){
if ( ( !isset( $value ) ) || ( $value == "" ) ){
$value = "\t";
}else{
$value = str_replace( '"' , '""' , $value );
$value = '"' . $value . '"' . "\t";
}
$line .= $value;
}
$data .= trim( $line ) . "\n";
}
$data = str_replace( "\r" , "" , $data );
if ( $data == "" ){
$data = "\n(0) Records Found!\n";
}
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=emails.xls");
header("Pragma: no-cache");
header("Expires: 0");
print "$header\n$data";
?>
Can anyone help me out with this? or if there is a simpler way that would be great. Cheers