up vote 2 down vote favorite
share [g+] share [fb]

As you may know, I am programming an on-line game using FLASH. I am connecting my FLASH 8 movie with MySQL database through PHP. I am doing very good in that, and I have everything working fine.

The problems come when I am trying to insert (Using the INSERT SQL func) data to the database that are non-english. In other words, UTF-8 data.

I red a lot of articls about that stuff and found and apply the fallowing: 1. In PHP4, you need to tell the PHP to use UTF-8 when using the xml_parser_crater() func, however, in PHP5 that is done automatically. Even though I told PHP5 to use the UTF-8 when calling the func.

  1. Adding the header to the XML sent to PHP from flash.

  2. Force the FLASH to use UTF-8 encoding in the preference options.

  3. Set the encoding in MySQL to UTF-8 (utf8_unicode_ci with InnoDB engine). I can read and insert the other language data correctly in the phpadmin as well.

I did all that in my coding, and still I can't insert such data.

one more strange thing is that, when I use the same link, that the FLASH using, with the XML, that the FLASH creating, on the browser (google chrome), I got the data inserted right in the database!!!!!

I am about to get crazy about that stuff, What am I missing? what cause the problem?

Thank you in advance.

link|improve this question
What is your collation set to in the mysql table you are trying to insert into? – Roger Davis Jan 9 '11 at 8:50
utf8_unicode_ci for the entier database and fields. And I am using the InnoDB engine. – Ali Albahrani Jan 9 '11 at 8:50
1  
Could you post an example what gets inserted into the DB (when sent from flash) and what you were sending originally? – bummzack Jan 9 '11 at 9:41
1  
Also: Use a tool like Firebug (getfirebug.com) to debug what flash sends to the server. – bummzack Jan 9 '11 at 10:45
well, this is an example of what flash is sending (localhost/Asmsam/…; encoding="UTF-8"?><worlds><wname>ارض الحياة</wname><wdisc>منطقة غنية بالمواقع الطعام</wdisc></worlds>) When I use this excatly the same in the browser, the data is inserted correctly - with correct encoding- but when the FLASH send it, the PHP code just stoped and can't insert anything to the database! – Ali Albahrani Jan 9 '11 at 12:11
show 3 more comments
feedback

4 Answers

I think you need to ditch the mysql_* functions and switch to something better like mysqli_* or PDO. See http://maurus.net/weblog/2006/07/28/typo3-php-mysql-connections-and-unicode/

link|improve this answer
feedback

Right after the call to mysql_connect/mysql_select_db execute this:

mysql_query('set character set utf8');

to tell the PHP-MySQL driver to use UTF-8

link|improve this answer
I did that, but I still facing the same problem! – Ali Albahrani Jan 23 '11 at 9:43
feedback

are you escaping with mysql_real_escape_string() ?

link|improve this answer
Yes, I tried that but no good news – Ali Albahrani Jan 28 '11 at 6:45
feedback

Well, as a result of my study so far about the problem, I found that the xml_parser can't read the data written in UTF-8 format. In other words, it stops when reaching such data reporting an error 'Invalid character'.

link|improve this answer
I 4get two things: FIRST: Is there any setting required to be made on the Appatch server to handle such things? SECOND: My Laptop, which I work on, is a 64-bit. Does that change anything in the issue? – Ali Albahrani Mar 1 '11 at 10:26
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.