当前位置: 动力学知识库 > 问答 > 编程问答 >

php - failed to import utf16 encoded file into mysql

问题描述:

I have txt pipe-delimited file (non-english - given below is Polish, but other langs are also involved), encoded utf16, something like:

head1|head2|head3|head4

brytyjski wytwórca|z jakże bogatą|przedwojenną historią|zapowiedział wypuszczenie

dziś znamy|jedynie paletę kolorów|obejmującą aż|jedną pozycję

I tried lots of different ways to get it into mysql table:

  • line-by-line using php

  • using LOAD DATA INFILE via console in any way I could conceive, e.g.:

LOAD DATA INFILE 'C:/\wamp/\www/\hmvc/\prop_tst.txt' INTO TABLE hmvc.table CHARACTER SET 'utf8' FIELDS TERMINATED BY '|' LINES TERMINATED BY '\n' \g

I always get either:

  • garbled (wrongly encoded) entries

  • nothing gets entered (sql writes default values)

Just to mention: I also set table in utf8, utf16, latin2 (for Eastern European encoding) ... and nada.

BTW:

When I change encoding , e.g. in Notepad to utf8 I can import - no problem, but what if I have chars requiring utf16 (Asian), or I want to automate file input?

Php iconv etc. seems not to be up to the job.

Any help, link to some reading etc. would be much appreciated, as I am freshly out of ideas.

网友答案:

As documented under LOAD DATA INFILE Syntax:

 Note

It is not possible to load data files that use the ucs2, utf16, or utf32 character set.

UTF-8 can represent the same full set of Unicode codepoints as UTF-16. Perhaps it'd be easiest to use only that encoding (or transcode the file prior to import in some other language, such as via PHP's iconv() function)?

分享给朋友:
您可能感兴趣的文章:
随机阅读: