views:

32

answers:

2

I recently converted an old MySQL database stored as latin1_swedish_ci to utf8_general_ci. I've now got the the HTTP header specifying UTF-8, the HTML tag on the page, and the data in the database is correctly encoded as utf8_general_ci.

It all works fine on my testing server, so I upload the updated HTML files and PHP scripts to the staging area on the live server. Then I replace the old staging database with an export from the test database.

And now, there are unicode entities instead of every apostrophe on the staging site.

Same database, same code, but it doesn't work there.

The difference between the test server and the staging area is that test server is the following:

Test:

  • Apache 2.2.15
  • PHP 5.3.2
  • MySQL 5.1

Staging: (Yes, it's horribly outdated, but it's out of my control)

  • Apache 1.3.37
  • PHP 5.2.3
  • MySQL 4.1.15

Any idea what is causing it not the work on the staging server?

+1  A: 

The connection encoding is really important here. Make sure you use the same encoding on both servers. For example by issuing this as the first command when you connect:

SET NAMES 'utf8';
Emil Vikström
This solved it. I had to add it to my DB set up code in the PHP script. Why is this necessary on one server and not the other?
Macha
The two servers probably have different default encodings. On one server you got the correct connection encoding automatically, on the other you got wrong encoding. It's always best to set it manually every time to be safe.
Emil Vikström
A: 

Make sure the following is set on each machine's my.cnf you're running mysql on:

[client]
default-character-set=utf8 

...

[mysqld]
default-character-set=utf8 
Mark L