Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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 stackoverflow.com 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

2 Answers 2

up vote 3 down vote accepted

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

default-character-set=utf8 
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:

mysql_set_charset('utf8',$link);
// or in OOP style:
$mysqli->set_charset('utf8');
share|improve this answer

Your Answer

 
discard

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.