Arabic text from mySQL database using amfphp

I had this issue where arabic text and french text retrieved from a mySQL database were not displaying correctly in my flash frontend, I was using amfphp to communicate and query the database. Needless to say that the text does display correctly in phpMyAdmin so it is correctly encoded in the database itself.

So here’s what I did to resolve the issue:

– Ensure that the mySQL tables where the text is stored are using the utf8_general_ci Collation.

– Set $gateway->setCharsetHandler( “none”, “ISO-8859-1”, “ISO-8859-1” ) in the gateway.php file (in case you’re wondering, yes you should simply NOT use iconv or utf_decoder or mbstring or the like, just disable the setCharsetHandler conversion by using “none” as the conversion method).

– in your php service file, say it’s called permissions.php, use the following :

$rsConnectionID=mysql_connect("localhost", "root", "");
mysql_set_charset("utf8", $rsConnectionID);

Be sure to have these set before running your query or passing the results to flash.

This should resolve all the issues you’re having, of course you should not use the following actionScript : system.useCodepage = true; as this will tell the flash player not to use utf 8 as default encoding and will surely get you into troubles.

Leave a Reply