1

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/ | +--------------------------+----------------------------+

agustinaliagac
  • 829
  • 10
  • 24
  • This might help to debug the problem and keep a certain order: http://stackoverflow.com/a/11413251/1163786 The checks remain the same, even if your target charset is different. – Jens A. Koch Sep 10 '15 at 18:50
  • Have you correctly set the [character set of your database connection](https://dev.mysql.com/doc/en/charset-connection.html)? – eggyal Sep 10 '15 at 18:59
  • should I change character_set_results to "latin1"? . The previous server had all this variables set as "utf-8" ( except "character_set_filesystem" ) and it worked.. – agustinaliagac Sep 10 '15 at 19:08

1 Answers1

1

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

O. Jones
  • 103,626
  • 17
  • 118
  • 172