Afdrukken
Categorie: MySQL
Hits: 1777

How to import CSV file to MySQL table

 

PHP Query for import csv file to mysql database

$query = <<<EOF
            LOAD DATA LOCAL INFILE '$file'
             INTO TABLE users
             FIELDS TERMINATED BY ','
             LINES TERMINATED BY '\n'
             IGNORE 1 LINES
            (name,mobile,email)
    EOF;

 

 

** Sample CSV file data **

name,mobile,email
Christopher Gritton,570-686-3439,ChristopherKGritton-at-inbound.plus
Brandon Wilson,541-309-5149,BrandonMWilson-at-inbound.plus
Craig White,516-795-8065,CraigJWhite-at-inbound.plus
David Whitney,713-214-3966,DavidCWhitney-at-inbound.plus