Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I use mysql_connect to a database solely defined in UTF-8. Everywhere I can look in the configuration, I see UTF-8 Unicode (utf8) or utf8_general_ci.

However, when I open the PHP connection, then use echo mysql_client_encoding();, I get latin1 as an output, which is pretty unexpected. Is it taken from some kind of PHP/Apache configuration?

share|improve this question

migrated from Jul 12 '11 at 7:24

This question came from our site for professional and enthusiast programmers.

Belongs to ServerFault – genesis Jul 11 '11 at 16:37
up vote 3 down vote accepted

In /etc/mysql/my.cnf add this line under [client]

share|improve this answer

You have to set the encoding for your PHP MySQL connection as it does not read it from your table/database definition. Do it like this:

// or in OOP style:
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.