quarta-feira, 30 de setembro de 2009

Setting Different Character Sets in MYSQL/PHP

I encountered a problem this week while updating the http://www.dancaiberica.org website for Dance Algarve 2010.

The site runs off a PHP/Myssql Database setup hosted on Godaddy shared hosting and servers pages in 4 different languages. This year I introduced a javascript dropdown menu that required the strict code in the header.

All was fine until the page were served up. Despite the fact the collation in the database is set to Latin_bin_1 and the following line is included in the header

meta http-equiv="Content-Type" content="text/html; charset=utf-8",

certain browsers were not rendering the Portuguese Characters correctly unless you manually changed the encoding in the browser each time one viewed the page. Needless to say the main culprit behind all this was Microsoft whose IE6/7/8 caused the original problem.

Anyway, after a bit of searching I found the following thread that resolved the issue:




"mysql_query("SET NAMES 'utf8'");"

to your php database connection string/file.

Problem solved!

Sem comentários: