PHP MySQL 希腊字母显示为 ???? 分数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11806319/
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 Greek letters showing like ???? marks
提问by Suneth Kalhara
I have a table with some text and text is greek letters, when i use sql tool and select the data from this table is showing correctly

我有一个包含一些文本的表格,文本是希腊字母,当我使用 sql 工具并从该表格中选择数据时显示正确

But when i show this my site frontend using mysql_fetch array and when echo it shows as below

但是当我使用 mysql_fetch 数组显示我的站点前端时,当回显时它显示如下

Anyone know how to fix this error thank you.
任何人都知道如何解决此错误,谢谢。
回答by MilMike
try the following:
尝试以下操作:
after you connect to the mysql, do this query to make sure that you are using UTF8:
连接到 mysql 后,执行此查询以确保您使用的是 UTF8:
mysql_query("SET NAMES 'utf8'");
mysql_query("SET CHARACTER SET 'utf8'");
make sure that in HTML (head) you are using the right encoding, try:
确保在 HTML (head) 中使用正确的编码,请尝试:
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
if this does not help, try different encoding, like ISO-8859-1
如果这没有帮助,请尝试不同的编码,例如 ISO-8859-1
回答by Marios
Try this:
尝试这个:
mysqli_set_charset($con, "utf8");
After you connect to DB.
连接到数据库后。
回答by eyecatchUp
Leaving this here for those who come to this site via Google because they have the same issue but use PDO instead (like me) - you should be fine with:
把这个留给那些通过谷歌访问这个网站的人,因为他们有同样的问题,但使用 PDO(像我一样) - 你应该没问题:
$dns = "mysqli:host=localhost;dbname=db_name";
$pdo = new PDO($dns, 'db_user', 'db_pass',
array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'));
$pdo->exec("SET CHARACTER SET 'utf8'");
回答by Paschalis
I wasted many hours till i figured this out.
我浪费了很多时间,直到我想通了这一点。
Intro:Greek characters were appearing wrong in mysql. I applied qxxxanswer in PHP and worked fine. Then I had to migrate everything to a new host, and then the problem reappeared.
介绍:希腊字符在 mysql 中出现错误。我在 PHP 中应用了qxxx答案并且工作正常。然后我不得不将所有内容迁移到新主机,然后问题再次出现。
What was wrong?
哪里错了?
The MySQL's schema charset was set to latin. The stored procedures had inherited MySQL's schema charset for their parameters.
MySQL 的模式字符集设置为拉丁语。存储过程的参数继承了 MySQL 的模式字符集。
So what I did:
所以我做了什么:
Dropped MySQL procedures/functions (make sure you backup your code)
Changed default charset of MySQL (using MySQL Workbench, right click on your database name-has a db icon..)
re-created the MySQL procedures/functions
删除 MySQL 程序/函数(确保备份代码)
更改 MySQL 的默认字符集(使用 MySQL Workbench,右键单击您的数据库名称 - 有一个 db 图标..)
重新创建 MySQL 程序/函数
Also, I left intact the qxxx's fix!
另外,我完整地保留了qxxx的修复程序!
回答by nata Kart
You don't have to drop tables or anything. Use MySQL Workbench and go to each table. Change the Collation to utf8 - default collation or utf8 - general ci. Then do the same for each column with type Varchar - it is found at the bottom of the window.
您不必删除表或任何东西。使用 MySQL Workbench 并转到每个表。将排序规则更改为 utf8 - 默认排序规则或 utf8 - 一般 ci。然后对 Varchar 类型的每一列执行相同的操作 - 它位于窗口底部。
回答by Jyotirmoy
I faced the same problem while implementing Greek Characters. The solutions like mysql_query("SET NAMES 'utf8'");
mysql_query("SET CHARACTER SET 'utf8'");did not work for me. After Googling, I found that, the character set for the database collation should be made greek_general_cialong with the field where data would be stored like categoryname etc. This solved my problem.
我在实现希腊字符时遇到了同样的问题。像 mysql_query("SET NAMES 'utf8'");
mysql_query("SET CHARACTER SET 'utf8'");这样的解决方案对我不起作用。谷歌搜索后,我发现,数据库整理的字符集应该greek_general_ci与存储数据的字段一起制作,如类别名称等。这解决了我的问题。

