Export to CSV via PHP

前端 未结 7 2527
没有蜡笔的小新
没有蜡笔的小新 2020-11-22 06:14

Let\'s say I have a database.... is there a way I can export what I have from the database to a CSV file (and text file [if possible]) via PHP?

7条回答
  •  耶瑟儿~
    2020-11-22 06:32

    Just like @Dampes8N said:

    $result = mysql_query($sql,$conecction);
    $fp = fopen('file.csv', 'w');
    while($row = mysql_fetch_assoc($result)){
        fputcsv($fp, $row);
    }
    fclose($fp);
    

    Hope this helps.

提交回复
热议问题