06 December 2010

Fix MySQL Character Encoding Problem UTF-8 PHP

While gathering data from Mysql database i got character encoding problems when my tables have non-english text.
I found a solution that completly solves character encoding problem while you calling your sql queries.

Simply set your character set before you call a sql query.
$myconnection= mysql_connect(DB_SERVER, DB_USER, DB_PASS)
or die(mysql_error());
mysql_select_db(DB_NAME, $myconnection) or die(mysql_error());

mysql_set_charset method sets your character set before the calls.
Don't forget to encode your php files to utf-8, or what encoding you want to encode with.

No comments: