如何在我的数据库中的字符上存储重音符号 [英] how to store accent marks over characters in my database

查看:63
本文介绍了如何在我的数据库中的字符上存储重音符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将地理编码的Google响应存储到我的数据库中.

I'm storing responses from the google geocoded into my database.

其中一个这样的回答在o上带有重音标记.小镇是林孔.(我会在此处标出重音符号,但我不知道该怎么做.)

One such response has an accent mark over the o. The town is Rincon. (I would put the accent mark here to show you, but I don't know how.)

当响应存储到我的mySQL数据库中时,它看起来像这样:Rincón

When the response is stored into my mySQL database it looks like this: Rincón

我意识到这与归类有关,但是我对更改数据库感到不安,因为那里有很多数据.当前应用于此字段的排序规则为utf8_general_ci.

I realize that this has to do with Collation, but I'm nervous about making changes to the database because I have so much data in there. The Collation that is currently applied to this field is utf8_general_ci.

任何人都可以建议:1)utf8_general_ci是正确的归类.2)我需要以某种方式在我的Ajax请求中指定此归类吗?

Can anyone advise: 1) Is utf8_general_ci the correct Collation. 2) Do I need to somehow specify this Collation in my ajax request?

谢谢....

推荐答案

UTF-8(通常)是世界上任何字符集的安全"编码.(并非总是最有效的,而且有一些论点认为Unicode的统一汉"模型不能很好地代表CJK脚本,但仍在继续……)

UTF-8 is (generally) a "safe" encoding for any character set in the world. (Not always the most efficient, and there are some arguments to be made that Unicode under-represents the CJK scripts with its "unified han" model, but moving on…)

但是,很可能您的接口程序没有正确地从UTF-8进行翻译.例如,ó=>ó看起来像是使用单字节欧洲编码(例如ISO-8859-15或MS-CP-1451或类似产品.

However, it's likely that your interface program(s) are not translating to/from UTF-8 properly. For example, ó => ó looks like the UTF-8 data (where one character can be spread across a varying number of bytes) is being presented to you using a single-byte European encoding, like ISO-8859-15 or MS-CP-1451 or similar.

可能正确存储了数据,但是加载不正确.如果您仅使用 mysql 终端程序或类似程序,请确保将终端设置为使用UTF-8(在Unix/Linux系统上, locale .utf8 结尾的内容,例如我的 LANG = en_US.utf8 )

You are probably storing the data correctly, but loading it incorrectly. If you're just using the mysql terminal program or similar, make sure that your terminal is set to use UTF-8 (on a Unix/Linux system, locale should probably be something ending in .utf8, e.g. mine has LANG=en_US.utf8)

如果要使用GUI工具或类似工具提取数据,请检查其设置/首选项"面板中的字符集.

If you're pulling data using a GUI tool or similar, check its Settings/Preferences panel for the character set.

如果您将误译的字符重新输入到编写的应用程序中,请查看您的语言设置语言环境的工具.(也许, INSERT 例程正确,但是 SELECT 例程错误?)

If you're getting the mistranslated characters back into an application you've written, look at your language's tools for setting the locale. (Perhaps, the INSERT routines have it right, but the SELECT routines have it wrong?)

如果将其发送到Web,请确保您的(XML | HTML | XHTML)文件在相应的位置从数据库插入文本时,使用 iconv 之类的东西将UTF-8转换回文档的字符集(如果可能).(当然,大多数非Unicode字符集只能代表Unicode的一个子集;例如,ISO-8859-15集在覆盖欧洲语言方面做得不错,但是不支持西里尔文,阿拉伯文或CJK书写系统,因此在Perl中,您可以使用传递参数来 open 或使用 binmode 在文件句柄"上设置透明字符集转换层.流.

And, if this is being sent to the Web, make sure your (XML|HTML|XHTML) files have charset=utf8 declared in the appropriate place(s), or translate back from UTF-8 to the character set of your document (if possible) using something like iconv when inserting text from the database. (Most non-Unicode character sets can only represent a subset of Unicode, of course; e.g. the ISO-8859-15 set does a decent job at covering European languages, but has no support for Cyrillic, Arabic, or CJK writing systems, so it's possible to fail to translate a character.) In Perl, you can use pass arguments to open or use binmode to set up a transparent character set translation layer on a "filehandle" stream.

这篇关于如何在我的数据库中的字符上存储重音符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆