我为我的问题找到了很多答案,但没有任何效果。 我的 MYSQL 数据库中有中文字符,当我在 php 中选择我的字段时,我得到“???”而不是“我们的产品”。我能够将这些字符从 php 插入到我的 MYSQL 数据库中。
对于像“éà”这样的字符,我可以毫无问题地在 PHP 中获取它们。
我的数据库、表和字段都是用utf8_unicode_ci编码的。这是我的 php 文件(也以 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']);
?>
如果我像这样替换我的代码,它会打印我们的产品:
$query = mysql_query("SELECT '我们的产品'");
arr = mysql_fetch_array($query)
echo ($arr[0]);
我希望我提供了足够的信息。
最佳答案
在进行mysql查询之前将字符集设置为utf8,如下所示
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');
关于php - MYSQL 转PHP 无法获取汉字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31141420/