我无法从MYSQL到PHP获取汉字 [英] I can't get Chinese characters from MYSQL to PHP

查看:91
本文介绍了我无法从MYSQL到PHP获取汉字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为我的问题找到了很多答案,但没有任何效果. 我的MYSQL数据库中有汉字,当我在php中选择字段时,我得到"???"而不是我们的产品".我能够将此字符从php插入到我的MYSQL数据库中.

I found a lot of answers for my problem but nothing worked. I have Chinese characters in my MYSQL database and when I SELECT my field in php I get '???' instead of '我们的产品'. I was able to INSERT this characters from php to my MYSQL database.

对于像'éà'这样的字符,我可以毫无疑问地用PHP获得它们.

With characters like 'éà' I have no problem to get them in PHP.

我的数据库,表和字段都编码为utf8_unicode_ci.有我的php文件(也用utf-8编码):

My database, table and field are encoded in utf8_unicode_ci. There is my php file(also encoded in utf-8) :

<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<?php
$query = mysql_query("SELECT * FROM table");
$arr = mysql_fetch_array($query))
echo ($arr['field']);
?>

如果我这样替换我的代码,它将打印出我们的产品:

If I replace my code like this it prints 我们的产品 :

$query = mysql_query("SELECT '我们的产品'");
arr = mysql_fetch_array($query)
echo ($arr[0]);

希望我能提供足够的信息.

I hope I gave enough information.

推荐答案

在进行mysql查询之前,将字符集设置为utf8

set charset as utf8 before making a mysql query, like this

mysql_connect('localhost','mysql_user','your_password');
mysql_select_db('my_db') or die( "Unable to select database");
mysql_set_charset('UTF8');
mysql_query('Your query here');

这篇关于我无法从MYSQL到PHP获取汉字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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