Thursday, September 06, 2007

MySQL + PHP + UTF-8 = ????

The title is not a question. It actually describes a common problem: i.e., when UTF-8 characters stored in MySQL is queried through PHP
they displayed as question marks on the web page. The solution (courtesy of Shawn Olson) is call this before any of your database manipulation code:

mysql_query("SET NAMES 'utf8'");

BTW, I host my site and MySQL database at GoDaddy and it supports UTF-8 "out of the box" without any special config.

No comments: