Re: PHP export to CSV

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



using mysql as an example, this is what i do.

---UNTESTED CODE --
$sql = "SELECT * FROM TABLE";
$res = mysql_query($sql) or die(mysql_error() . "<br>".$sql);
$fp = fopen("file_to_create.csv", "w");

while ($rs = mysql_fetch_row($res)) {
      $write_string = "\" . implode("\",\"", $rs) . "\" \n";
      fwrite($fp, $write_string);
}
fclose($fp);

This would produce a fully quoted csv file.  edit to you liking.

hth
Jeff




                                                                                                                                        
                      "John Greco"                                                                                                      
                      <john@xxxxxxxxxx>        To:       php-db@xxxxxxxxxxxxx                                                           
                                               cc:                                                                                      
                      12/22/2003 10:20         Subject:   PHP export to CSV                                                     
                      AM                                                                                                                
                      Please respond to                                                                                                 
                      "John Greco"                                                                                                      
                                                                                                                                        
                                                                                                                                        




Anyone ever get some code to select from the DB and drop into a CSV file?

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux