如何在mysql中编码西里尔字母? [英] How to encode cyrillic in mysql?

查看:100
本文介绍了如何在mysql中编码西里尔字母?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

怎么了? :-)
我有一个问题,希望您能为我解决.

what's up? :-)
I have one problem and i hope you can help me with it.

我的一个朋友有一个简单的html网站,我实现了很少的php;用于文章的CRUD系统...我遇到的问题是从mysql数据库中放置西里尔字符.

One friend of mine have a simple solid html website and i implemented little php; CRUD system for articles... problem i came across is placing and getting cyrillic characters from mysql database.

下一个我想达到的目标:
在主导航中,有一些单独的部分,它们的名称,id和项的顺序我想放在mysql中,而不是提取名称并将每个名称作为链接.名称应该是西里尔字母.

What i want to achive is next:
In the main navigation there are some separated sections, whose names, ids and item's order i want to place in mysql and than to pull names and to put each name as a link. Names are supposed to be cyrillic characters.

当我使用php mysql_fetch_assoc函数尝试显示在数据库行中插入西里尔字符的名称,行的排序规则为utf8_general_ci,并且我以?????结尾并插入原始字符时,就会出现问题.如果我通过提交表单向mysql提交西里尔字母,则会显示类似У.

The problem comes when i, using php mysql_fetch_assoc function, try to display names which are inserted with cyrillic characters in database row, collation of row is utf8_general_ci, and i end with ????? insted of original characters. If i submit cyrillic characters via submit form to mysql it shows something like this У.

我要如何解决这个问题,谢谢!! :-)

How can i solve this, thanks in advance!? :-)

推荐答案

请确保在连接数据库后调用此名称.

Make sure you call this after connecting to database.

mysql_query("SET NAMES UTF8");

还要确保HTML文件的字符集元标记设置为UTF-8或在输出之前发送标头.

Also make sure that HTML file has charset meta tag set to UTF-8 or send header before output.

header("Content-Type: text/html; charset=utf-8");

这篇关于如何在mysql中编码西里尔字母?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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