Encoding problems between UTF

I'm changing a website (PHP, MYSQL) to another server, where I'm configuring it in a Linux - Apache environment. The problem is that some pages are displaying character encoding errors. The data is stored in mysql as latin1_swedish_ci , and the php files involved are also encoded in iso-8859-1 . PHPMyAdmin, however, displays this data correctly if I make a query. HTTP headers are showing "text/html; charset=iso-8859-1" so nothing wrong there.

I don't know where to look to fix this issue. I don't know if it's an Apache problem, or PHP that somehow tries to read data as utf-8 instead of what it really is .

This is currently the output of " SHOW VARIABLES LIKE '%char%'; "

+--------------------------+----------------------------+ | Variable_name | Value | +--------------------------+----------------------------+ | character_set_client | utf8 | | character_set_connection | utf8 | | character_set_database | latin1 | | character_set_filesystem | binary | | character_set_results | utf8 | | character_set_server | latin1 | | character_set_system | utf8 | | character_sets_dir | /usr/share/mysql/charsets/ | +--------------------------+----------------------------+


Your data isn't stored as latin1_swedish_ci, it's stored as latin1. That is also known as iso-8859-1; they are the same thing. The Swedish part is the collation. It's a common point of confusion.

Your connection to your database, at least the one you used to display your system variables, is set to utf8. That's not latin1.

You should, when you establish your connection to the database, issue this command right away, both in php and when you use an interactive client program.

SET NAMES latin1

You can read about this here: https://dev.mysql.com/doc/refman/5.6/en/charset-connection.html

链接地址: http://www.djcxy.com/p/25134.html

上一篇: 替代大量的MySQL布尔值?

下一篇: 编码UTF之间的问题