Jump to content

Any Sql For Exporting Data To Csv


tinfanide

Recommended Posts

phpmyadmin is written in PHP, so you can always get the source and look at the export commands. It's not a single line of code, it gets the data first and then outputs it. You can use this function to output an array as a line of CSV text:

function array2csv ($fields, $delimiter = ',', $enclosure = '"', $mysql_null = false){  $delimiter_esc = preg_quote($delimiter, '/');  $enclosure_esc = preg_quote($enclosure, '/');  $output = array();  foreach ($fields as $field)  {    if ($field === null && $mysql_null)    {      $output[] = 'NULL';      continue;    }    $output[] = preg_match('/(?:'.$delimiter_esc.'|'.$enclosure_esc.'|\s)/', $field) ? (    $enclosure . str_replace($enclosure, $enclosure . $enclosure, $field) . $enclosure    ) : $field;  }  return join($delimiter, $output);}

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...