Jump to content

Any Sql For Exporting Data To Csv


tinfanide
 Share

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...