简体   繁体   English

希腊字符无法正确显示到数据库/从数据库正确显示-html,php,mysqli

[英]greek characters not appearing correctly to/from database - html, php, mysqli

My database has collation utf8-general-ci [I also tried greek-general-ci with worse results]. 我的数据库具有排序规则utf8-general-ci [我也尝试了greek-general-ci ,但结果较差]。

When I insert a row with Greek values directly through phpMyAdmin, it appears on my html page like this: '??????'. 当我直接通过phpMyAdmin插入带有希腊值的行时,它在我的html页面上显示为:'??????'。

When I insert a row through my html form, it appears correctly on the html-outcome page, but on phpMyAdmin it looks like this: 'ΜαÏία'. 当我通过html表单插入一行时,该行正确显示在html-outcome页面上,但是在phpMyAdmin上,它看起来像这样:“α-β-β”。

I can deal with that, since I'm only doing this for a university project, so I can just insert all rows through my html form, but I'm really curious why this is happening. 我可以解决这个问题,因为我只是在大学项目中这样做,所以我可以通过html表单插入所有行,但是我很好奇为什么会这样。

On my html files I have <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> and when I had header('Content-Type: text/html; charset=utf-8'); 在我的html文件上,我有<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">并且当我有header('Content-Type: text/html; charset=utf-8'); on my php files it messed seriously with my pages so I must not include it. 在我的php文件上,它严重弄乱了我的页面,因此我不能包含它。 Also tried including $mysqli->set_charset("utf8"); 还尝试包括$mysqli->set_charset("utf8"); but only errors appeared. 但只会出现错误。

I have also checked Greek characters encoding works in HTML but not in PHP but we don't have the same problem. 我还检查了希腊字符编码在HTML中的工作原理,但在PHP中没有,但是我们没有同样的问题。 Should I change the httpd.conf file however? 但是,我应该更改httpd.conf文件吗?

First of all check your table's collation. 首先检查表的排序规则。 It's not linked to database collation. 它没有链接到数据库排序规则。 Your table collation should be utf8-general-ci too. 您的表排序规则也应为utf8-general-ci。

<? header('Content-Type: text/html; charset=utf-8'); 
$mysqli->set_charset("utf8"); ?>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">

When all these four settings are active; 当所有这四个设置都激活时; You should able to insert, update or read UTF-8 INSERTED data successfully 您应该能够成功插入,更新或读取UTF-8插入数据

My guess is your problem occured because your old data is not utf-8 encoded. 我的猜测是您的问题发生了,因为您的旧数据不是utf-8编码的。 You should create a batch script; 您应该创建一个批处理脚本;

  1. which selects all data from table 从表中选择所有数据
  2. convert it to utf-8 using mb_convert_encoding 使用mb_convert_encoding将其转换为utf-8
  3. and updated old data 和更新的旧数据

to fix your data. 修复您的数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM