从排序规则 Modern_Spanish_CI_AI(在 SQL Server 中)到 UTF-8(在 MySQL 中)
我正在编写一个 PHP 脚本,将一些数据从 Microsoft SQL Server 数据库导入到我的 MySQL 数据库。
SQL Server 中的排序规则是 Modern_Spanish_CI_AI (所以我猜编码是 ASCII),在我的 MySQL 数据库中,我使用 UTF-8 编码和 utf8_unicode_ci 作为排序规则。
当我导入数据时,我得到了与西班牙语字母 Ñ 相对应的错误字符。我尝试使用 PHP 函数 utf8_encode($string) 和 mb_convert_encoding($string, "UTF-8") 但没有成功,(我得到了不同的错误字符,但仍然错误)。
也许这有帮助: SQL Server 中表的定义:
CREATE TABLE [dbo].[myTable] (
[myField] varchar(2) COLLATE Modern_Spanish_CI_AS NOT NULL,
MySQL 中表的定义
CREATE TABLE `myTable` (
`myField` varchar(2) COLLATE utf8_unicode_ci NOT NULL,
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,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我没有使用 SQL Server 的经验,但粗略地浏览了 this排序规则图表,
Modern_Spanish_CI_AI
似乎本质上是 Windows-1252 字符集,可能在顶部有一些西班牙语排序/比较规则。您应该能够像这样转换数据:
尝试一下。然而,当使用 PHP 实现此目的时,每个数据库连接的字符集也会发挥作用 - 如果仍然不起作用,则需要显示更多代码。
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:
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.