Xabby
Xabby

Reputation: 437

How i can create a csv file from a sql query with php

I have a SQL file that have some query in it i want to create a CSV file from this query. Current SQL file included the following code:

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',

Upvotes: 0

Views: 51

Answers (1)

PaulF
PaulF

Reputation: 6773

This can be done directly without PHP using the SELECT ... INTO OUTFILE FIELDS TERMINATED BY ',' command : http://dev.mysql.com/doc/refman/5.7/en/select-into.html

Upvotes: 3

Related Questions