MySQL - 俄语字符显示不正确
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4316290/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
MySQL - Russian characters display incorectly
提问by Mike
I have to make an russian version of a website, but I can't find out, how to insert russian characters into Database.
我必须制作一个网站的俄语版本,但我不知道如何将俄语字符插入到数据库中。
I tryed almost every possible coding, but it only shows:
我尝试了几乎所有可能的编码,但它只显示:
???????? ?????????? ??????? ??????? ? ????? ?? ????????????? ? ???????, ??????? ????? ??????? ???????? ????? .??? ??????????? ???????? ????? ?? ????? ?????????? ? ????? ????????.
??????????? ?????? ?? ???????? ????? ?? 20 ???????. ???????? ??? ?? ??????????? ?????????????? ????? ? ????????????? ??????? ??????. ? ???????, ? ??????? ? ?.?.
回答by meder omuraliev
- Make sure the database charset/collation is UTF-8
- On the page you insert these russian characters ( the form, textarea ), make sure the encoding is UTF-8, by setting Content-Type to
text/html; charset=utf-8
. Enter in russian text directly to the form input. - On the processing page that handles this form, which inserts it into the database, make sure to do
SET NAMES utf8
so it's stored as UTF-8 beforeyou insert the data, in a separate query beforehand. - When you render the content from the database in a view, make sure the
Content-Type
istext/html; charset=utf-8
.
- 确保数据库字符集/排序规则为 UTF-8
- 在您插入这些俄语字符(表单, textarea )的页面上,通过将 Content-Type 设置为 ,确保编码为 UTF-8
text/html; charset=utf-8
。直接在表单输入中输入俄文文本。 - 在处理此表单的处理页面上,将其插入到数据库中,确保在插入数据之前将其
SET NAMES utf8
存储为 UTF-8 ,事先在单独的查询中。 - 当你从渲染视图中的数据库中的内容,确保
Content-Type
为text/html; charset=utf-8
。
Make sure that the content-type is notwindows-1251 or iso-8859-1/latin1. Make sure the database charset/collation is NOT ISO-8859-1/Latin1.
确保内容类型不是windows-1251 或 iso-8859-1/latin1。确保数据库字符集/排序规则不是 ISO-8859-1/Latin1。
回答by Shubham Chopra
For storing russian characters in db your db should support UTF-8 encoding. Modify your table with below query to enable UTF-8 encoding.
为了在 db 中存储俄语字符,您的 db 应该支持 UTF-8 编码。使用以下查询修改您的表以启用 UTF-8 编码。
ALTER TABLE t1 CONVERT TO CHARACTER SET utf8