简体   繁体   中英

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.

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. But if I go to phpMyAdmin, all the latin characters are all messed up, something like ñññ.

If I try to fix that data in phpMyAdmin, then my website displays the data incorrectly, with weird symbols .

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.

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?

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.

Problem: Characters displayed correctly in phpMyAdmin, wrong in 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).

HTML code:

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

Solution: I've added in php (preceding any other queries):

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.

If phpMyAdmin is showing ñññ instead of ñññ , that's because it's interpreting a UTF-8 bytestream as ISO-8859-1. So your database contents are probably correct, phpMyAdmin is just showing them in a wrong manner.

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).

for Scuzzu's Question there are several ways:

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:

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

2- Look for [mysqld] entry and append:

  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!

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?

Just set mysql_query("SET NAMES utf8"); after mysql_connect line:

$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 . Following piece of code has to be included between a $conn check and an $sql query:

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

After doing mysql_query("SET names 'utf8';"); You need also to go to mySQL and define collation as UTF-8, also! This should solve your problem. Good luck!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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