CSV Export/Import Functions in PHP
Tagged with: csv, export, function, import, PHP
Functions to Export and import CSV data using PHP
//*Get the result of the query as a CSV stream.
function CSVExport($query) {
global $sql;
$sql_csv = $sql->getSqlHandle($query);
header("Content-type:text/octect-stream");
header("Content-Disposition:attachment;filename=data.csv");
while($row = mysql_fetch_row($sql_csv)) {
$row = $sql->_stripsls($row);
print '"' . implode('","',$row) . "\"\n";
}
exit;
}
Follow me(@binnyva) on Twitter
May 15th, 2008 17:56
OK, thanks.
But can you give me the functions : _stripsls (I thinks that is the same as stripslashes), and the class for this => “$sql->getSqlHandle($query);”.
Sorry for my english, but I’m french.
May 15th, 2008 23:06
Here is the latest version of $sql class
And here is the latest version of the CSV Import/Export functions – use this.
May 16th, 2008 13:17
Thanks so much.