Import csv file into mysql

I am using MySQL with php. Via php script I am trying to import a csv file with the following request

LOAD DATA LOCAL INFILE '$file' INTO TABLE userstable FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n' IGNORE 1 LINES (name, univ, mobile); 

I can successfully import the file into the database tables, but I can see hidden formatting characters (like in a word, powerpoint, etc.) in all cells under the last ie mobile column.

How to avoid inserting into a table

+4
source share
2 answers

Possible DOS line endings. Try using

  LINES TERMINATED BY '\r\n' 

instead.

+1
source

I think you'll have to use regular expressions to filter data before saving it. If I remember correctly, most of this formatting is standardized, so it needs to be easily found and fixed before adding it to your dB. - lee

0
source

All Articles