From collation Modern

I am writing a PHP script to import some data from a Microsoft SQL Server database to my MySQL database.

Collation in the SQL Server is Modern_Spanish_CI_AI (so I guess the encoding is ASCII), and in my MySQL database I'm using UTF-8 encoding and utf8_unicode_ci as collation.

When I import the data I get wrong characters corresponding to the Spanish letter Ñ. I've tried to use the PHP functions utf8_encode($string) and mb_convert_encoding($string, "UTF-8") without any success, (I got different wrong characters but still wrong).

Perhaps this helps: Table's definition in SQL Server:

CREATE TABLE [dbo].[myTable] (
[myField] varchar(2) COLLATE Modern_Spanish_CI_AS NOT NULL,

Table's definition in MySQL

CREATE TABLE `myTable` (
`myField` varchar(2) COLLATE utf8_unicode_ci NOT NULL,

I have no experience with SQL server, but from a cursory glance at this collation chart, Modern_Spanish_CI_AI seems to be essentially a Windows-1252 character set, probably with some Spanish sorting / comparison rules on top.

You should be able to convert the data like this:

$utf8 = iconv("windows-1252", "utf-8", $input);

try it out. However, when using PHP for this, the character set of the connection to each database also plays a role - if it still doesn't work, you need to show some more code.

链接地址: http://www.djcxy.com/p/25180.html

上一篇: 将字符串转换为UTF的最佳方法是什么?

下一篇: 从整理现代