AS3FlexDB and UTF8

Becouse I’ve received a lot of emails asking me how can AS3FlexDB can select UTF8 data from MySQL i have decided to write a post and explain how you can load UTF8 data from MySQL in Flex.

There are three steps you must done to accomplish this:

Step 1

Setup your MySQL table fields to support UTF8. You can do this by changing your collation to utf8_general_ci 

utf8_table_sample1

Step 2

Edit the AS3FlexDB service ( database.php ) on function open($strUser, $strPass, $strHost) line 37  after 

$rsConnectionID = @mysql_connect($strHost, $strUser, $strPass);

 add 

mysql_set_charset(‘utf8′, $rsConnectionID);

this function will set UTF8  character set for the current connection.

Step 3

Edit AMFPHP gateway.php file. The gateway.php file is the bridge between your flash .swf file and AS3FlexDB service (database.php). In this file all you need to change is the setCharsetHandler method.

Replace :

$gateway->setCharsetHandler(“utf8_decode”, “ISO-8859-1″, “ISO-8859-1″);

with :

$gateway->setCharsetHandler( “none”, “ISO-8859-1″, “ISO-8859-1″ );

and this is all. If you have done everything right you can now load UTF8 data from MySQL. 
If you want to read more about  character set in AMFPHP you can check this tutorial.

One thought on “AS3FlexDB and UTF8

  1. Alex,

    You have no idea what a problem you have solved here. I have been struggling with a right-to-left language and went through several hoops setting the database table a certain way, calling encode functions in PHP etc. from all kinds of posts I have read, even reversing the order of the words from the received data.

    Finally, your post, so simple and brings the data in as it was placed in the database, no need to make any hoops or workarounds (which makes sense in our technological times) I am so happy you came up on the first page in Google.

    Great post.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>