我如何使用php从sql查询创建一个csv文件

时间:2016-01-04 09:55:32

标签: php mysql sql-server csv

我有一个SQL文件,其中包含一些查询,我想从此查询中创建一个CSV文件。当前SQL文件包含以下代码:

SELECT
    ID AS 'Donor ID',
    directorsComments AS 'Director Comments',
    external_donor_id AS 'Donor Number',
    CASE
        WHEN is_approved = '1'
            THEN 'Approved'
        ELSE 'Not Approved'
    END AS 'Approval Status',

    donor_status AS 'Donor Status',
    screening_status AS 'Screening Status',
    Title AS 'Title',
    firstName AS 'First Name',
    lastName AS 'Last Name',

    dateStarted AS 'Created At',
    dateSubmitted AS 'Last Updated',
    ipAddress AS 'IP',

1 个答案:

答案 0 :(得分:3)

这可以在没有PHP的情况下直接使用SELECT ... INTO OUTFILE FIELDS TERMINATED BY','命令:http://dev.mysql.com/doc/refman/5.7/en/select-into.html