How to remove or avoid inserting column headers when importing a separated value file into a database using PHP?

后端 未结 3 1074
轻奢々
轻奢々 2021-01-24 09:42

I have semicolon-separated .dat file and I want to read that file and store its contents into a database.

Structure of .dat file:



        
3条回答
  •  时光取名叫无心
    2021-01-24 10:02

    This is a common task done daily by DBAs. It can be done in mysql with the LOAD command. No need to use PHP.

    http://dev.mysql.com/doc/refman/5.1/en/load-data.html

    LOAD DATA LOCAL INFILE 'file.dat' 
    INTO TABLE table_name
    FIELDS TERMINATED BY ';' 
    LINES TERMINATED BY '\n' 
    (PARTYID, PARTYCODE, CONNECTIONID)
    IGNORE 1 LINES;
    

提交回复
热议问题