You do not mention the version of MySQL you are using, but if you are using 5.0.7 or later, according to the official PHP documentation
This is the preferred way to change the encoding. Using mysql_query () to install it (e.g. SET NAMES utf8) is not recommended. For more information, see MySQL Character Set Concepts.
, for example, Assuming you are using the mysql_query extension.
<?php $link = mysql_connect('localhost','user1','pass1',TRUE); mysql_selectdb('db1', $link); mysql_set_charset('utf8',$link); ?>
Other considerations:
- Files used must be encoded using UTF-8
- The entire database, table and field must be encoded using
utf8_general_ci - PHP headers and HTML headers must also be set to UTF-8
As a side note, using the mysql_query extension is not recommended. Instead, use the MySQLi extension or PDO_MySQL ..
See also MySQL: API guide selection and related FAQ for more information.
source share