Jump to content

CVS files with PHP


Gnub

Recommended Posts

Im wondering if it is at all possible, for PHP to create a CVS file from a mySQL database. 

 

If there is a simple mysql - go create a CVS file, and drop it <here> .  Or will i have to go the long way round, and access the database, append each field in a record to a string, save the string to a file, and save it as a *.cvs file.

 

Your thoughts here would be great.

 

Cheers.

Link to comment
https://forums.phpfreaks.com/topic/38618-cvs-files-with-php/
Share on other sites

this will turn a table's data into csv in the format

'data', 'more date', 'more data'

 

may want to use addslashes

 

$sql = "SELECT * from table";
$result = mysql_query($sql);

while($row = mysql_fetch_object($result){
    $string = "";
        foreach($row as $var => $val){
            $string = $string."'".$val."', ";
        }
    echo "$string<br>";
}

Link to comment
https://forums.phpfreaks.com/topic/38618-cvs-files-with-php/#findComment-185342
Share on other sites

Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.