PHP mysql 字符集 utf8 问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14068616/
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
PHP mysql charset utf8 problems
提问by Samuele
Possible Duplicate:
UTF-8 all the way through
可能的重复:
UTF-8 一直通过
I'm developing some new features on a website that somebody else already developed.
我正在其他人已经开发的网站上开发一些新功能。
I'm having a problem the charset.
我的字符集有问题。
I saw that the database had some tables in utf8 and some in latin1
我看到数据库中有一些表是 utf8 的,一些表是 latin1 的
So I'm trying to convert all the tables in UTF8.
所以我正在尝试将所有表转换为 UTF8。
I did it for one table (also the fields of this table now are utf8), but was not successful.
我为一张表做了它(现在这个表的字段也是utf8),但没有成功。
I'm using the normal mysql connect. I have to put any config to say that it must connect with utf8 to the DB? If yes witch one?
我正在使用普通的 mysql 连接。我必须把任何配置说它必须与 utf8 连接到数据库?如果是女巫一?
In my html I have:
在我的 html 中,我有:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
It looks like some letters works and others display the question mark. For example it not able to display this ' that is different of this: '
看起来有些字母有效,而其他字母则显示问号。例如,它无法显示与此不同的“:”
回答by Codesen
Try this
尝试这个
<?php
header('Content-Type: text/html; charset=utf-8');
?>
and then in the connection
然后在连接中
<?php
$dbLink = mysql_connect($argHost, $argUsername, $argPassword);
mysql_query("SET character_set_results=utf8", $dbLink);
mb_language('uni');
mb_internal_encoding('UTF-8');
mysql_select_db($argDB, $dbLink);
mysql_query("set names 'utf8'",$dbLink);
?>

