简体   繁体   English

phpMyAdmin中的拉丁字符,带有UTF-8排序规则

[英]Latin characters in phpMyAdmin with UTF-8 collation

My website uses: 我的网站使用:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 

And this meta: 而这个元:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

I created my database and tables in phpMyAdmin making sure everything is set as utf8_unicode_ci (table, fields, database), even the connection collation. 我在phpMyAdmin中创建了我的数据库和表,确保所有内容都设置为utf8_unicode_ci(表,字段,数据库),甚至连接排序规则。

When I insert some latin characters (accents, ñ and stuff like that) into the database using an standard form made in PHP, it works fine, I can display the saved data in my website no problem. 当我使用PHP制作的标准表单将一些拉丁字符(重音符号,ñ和类似的东西)插入到数据库中时,它工作正常,我可以在我的网站中显示保存的数据没问题。 But if I go to phpMyAdmin, all the latin characters are all messed up, something like ñññ. 但是,如果我去phpMyAdmin,所有拉丁字符都搞砸了,类似于ññ。

If I try to fix that data in phpMyAdmin, then my website displays the data incorrectly, with weird symbols . 如果我尝试在phpMyAdmin中修复该数据,那么我的网站会错误地显示数据,并带有奇怪的符号 。

What in this world am I doing wrong? 在这个世界上我做错了什么? I've been trying to work this out for hours with no success. 我一直在努力工作几个小时而没有成功。

Thank you all! 谢谢你们!

As @Artefacto says, this could be a problem local to phpMyAdmin. 正如@Artefacto所说,这可能是phpMyAdmin的本地问题。

If phpMyAdmin is fine (ie set to UTF-8) and the data is still showing up weird, then look at whether your database connection using UTF-8 as well? 如果phpMyAdmin没问题(即设置为UTF-8)并且数据仍然显示奇怪,那么看看你的数据库连接是否也使用UTF-8?

mysql_query("SET NAMES utf8") 

(or whatever you use as a database library) might help if it isn't. (或者你用作数据库的任何东西)如果不是,可能会有所帮助。

mysql_query("SET NAMES utf8") solved my problem. mysql_query(“SET NAMES utf8”)解决了我的问题。

Problem: Characters displayed correctly in phpMyAdmin, wrong in HTML/PHP. 问题:在phpMyAdmin中正确显示字符,在HTML / PHP中显示错误。 Characters: â, î, etc. 人物:â,î等

The headers are ok (utf8), phpmyadmin displays the content in the correct form, but the website keeps showing weird question-mark characters (inside a black diamond character). 标题是好的(utf8),phpmyadmin以正确的形式显示内容,但网站不断显示奇怪的问号字符(在黑钻石字符内)。

HTML code: HTML代码:

<!DOCTYPE html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

Solution: I've added in php (preceding any other queries): 解决方案:我已经在php中添加(在任何其他查询之前):

mysql_query("SET NAMES utf8");

Other causes can lead to this behaviour; 其他原因可能导致这种行为; this is only one part of the solution. 这只是解决方案的一部分。 You may need to check content-type, web server configuration (httpd.conf), html lang / dir, charset, etc. However, question mark in a black diamond seems to be more specific to this problem/solution, in other cases are displayed 2-3 weird characters instead of the one you want. 您可能需要检查内容类型,Web服务器配置(httpd.conf),html lang / dir,charset等。但是,黑色菱形中的问号似乎更具体到此问题/解决方案,在其他情况下是显示2-3个奇怪的字符而不是你想要的字符。

If phpMyAdmin is showing ñññ instead of ñññ , that's because it's interpreting a UTF-8 bytestream as ISO-8859-1. 如果phpMyAdmin显示ñññ而不是ñññ ,那是因为它将UTF-8字节流解释为ISO-8859-1。 So your database contents are probably correct, phpMyAdmin is just showing them in a wrong manner. 所以你的数据库内容可能是正确的,phpMyAdmin只是以错误的方式显示它们。

I'm not familiar with the application, but you can force the browser to read the page as UTF-8 (typically View > Encoding > UTF-8). 我不熟悉该应用程序,但您可以强制浏览器将该页面读取为UTF-8(通常为View> Encoding> UTF-8)。

for Scuzzu's Question there are several ways: 对于Scuzzu的问题,有几种方法:

http://www.mysqlperformanceblog.com/2007/12/18/fixing-column-encoding-mess-in-mysql/ http://www.mysqlperformanceblog.com/2007/12/18/fixing-column-encoding-mess-in-mysql/

I would have eight more links with different tasks but this site is prevent me from saving them... 我会有八个不同任务的链接,但这个网站阻止我保存它们...

"as a spam prevention mechanism, new users can only post a maximum of one hyperlink" “作为垃圾邮件防范机制,新用户最多只能发布一个超链接”

1- Edit file: 1-编辑文件:

my.ini (MsWindos) my.ini(MsWindos)
my.cnf (GNU/linux) my.cnf(GNU / linux)

2- Look for [mysqld] entry and append: 2-查找[mysqld]条目并追加:

  character-set-server = utf8
  skip-character-set-client-handshake

The whole view should look like: 整个视图应如下所示:

[mysqld]
  port=3306
  character-set-server = utf8
  skip-character-set-client-handshake

3- Restart MySQL service! 3-重启MySQL服务!

If phpMyAdmin is fine (ie set to UTF-8) and the data is still showing up weird, then look at whether your database connection using UTF-8 as well? 如果phpMyAdmin没问题(即设置为UTF-8)并且数据仍然显示奇怪,那么看看你的数据库连接是否也使用UTF-8?

Just set mysql_query("SET NAMES utf8"); 只需设置mysql_query("SET NAMES utf8"); after mysql_connect line: mysql_connect行之后:

$con = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD) or die(mysql_error());
    mysql_query("SET NAMES utf8");

I was struggled with the same problem and finally found an elegant way to check and change collation via PHP function mysqli_set_charset . 我遇到了同样的问题,终于找到了一种通过PHP函数mysqli_set_charset检查和更改排序规则的优雅方法。 Following piece of code has to be included between a $conn check and an $sql query: 以下代码必须包含在$conn检查和$sql查询之间:

if (!mysqli_set_charset($conn, "utf8")) {
    printf("Error loading character set utf8: %s\n", mysqli_error($conn)); //optional row
    die();
}

I found the solution here: http://php.net/manual/en/mysqli.set-charset.php 我在这里找到了解决方案: http//php.net/manual/en/mysqli.set-charset.php

After doing mysql_query("SET names 'utf8';"); 做了mysql_query("SET names 'utf8';"); You need also to go to mySQL and define collation as UTF-8, also! 您还需要转到mySQL并将排序规则定义为UTF-8! This should solve your problem. 这应该可以解决您的问题。 Good luck! 祝好运!

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

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