开发者

CSV file to MySQL table, charset encoding problem

开发者 https://www.devze.com 2023-02-27 08:29 出处:网络
I\'m trying to load a CSv file into a mysql table, the problem is that the CSV file is \'iso-8859-1\' and my database is \'utf-8\'.

I'm trying to load a CSv file into a mysql table, the problem is that the CSV file is 'iso-8859-1' and my database is 'utf-8'.

I've use the following instruction:

LOAD DATA INFILE 'file.csv' INTO TABLE edes_objetivos_aux CHARACTER SET latin1 FIELDS TERMINATED BY ',开发者_高级运维' ENCLOSED BY '\"' LINES TERMINATED BY '!EOR' IGNORE 1 LINES (tipo_movimiento,@objetivo_k,nombre,descripcion,metrica_k,acumulativo,heredable,fecha_creacion,usuario_propietario_k,meta,resultado,heredado,acumulativo,porcentaje_avance,fecha_programada,fecha_inicio,fecha_finalizada,porcentaje_padre,periodo) SET objetivo_k=md5(@objetivo_k)

In the above example I'm using 'latin1' because that's the file's encoding, however, some characters are not right because my database is utf-8 :(

I can't change the file's encoding. Is there a way to replace the wrong characters? What can I do?

Thanks in advance :)


Try loading the CSV into php, running utf8_encode as per link, and then running an insert into your table. Does that work for you? (This might be better anyways because you can sterilize your CSV inputs this way and prevent DB injection)

0

精彩评论

暂无评论...
验证码 换一张
取 消