views:

80

answers:

2

Hi guys,

I'm pushing data from as3 to MSQL through a little php script!

My problem is that all my accentuated characters are displayed as weird iso characters.

Example : é is displayed %E9

Obvisously the collation of my field is set to utf8_general_ci

Even when I try to INSERT the data from a simple php script without as3, I get the same mistake.

<?php

mysql_connect("***", "***", "***") or die("Error :" .mysql_error());
mysql_select_db("***");


$query ="INSERT INTO test (message) values ('éèàïû')";

mysql_query($query) or die("Error updating DB");


?>

Any idea on what am I doing wrong and how I could fix that?

Thanks in advance.

Jk_

A: 

mysql do not urlencode your data. Some your code does it. May be at select time.

Aside from this problem, you should issue a SET NAMES <encoding> query every time you connect to the database, where <encoding> is your HTML page encoding

Col. Shrapnel
Thank you! Now it works when I use the php file only. But it doesn't work when I pass the query from as3. I have to figure it out why. Weird.
Jk_
@JK- you're getting urlencoded data. So, rawurldecode() it first.
Col. Shrapnel
A: 

The problem in this case could lie in a number of places: to ensure utf8 input compatibility, you have to check the input at several places:

  1. If you obtain the data from a form, make sure that you state the charset you're using is stated by the server (e.g. through AddCharset on Apache) or better yet, stated using a <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> statement. Note that if the server states that the encoding is latin1 and PHP has it set to utf8, the display can be wrong. As such, it is strongly recommended for you to have an in-header meta tag.

  2. In your PHP configuration, try to have the line default_charset = "utf8" . This should be the default, but just check. This controls the output charset, and if this does not agree with the Apache server or page charset, the utf8 may be output as ASCII, resulting in your problem. If you can't access php.ini, use ini_set to set this option in a common included file.

  3. Make sure you do mysql_set_charset('utf8'); after you connect to MySQL. This is important as it makes your connection to MySQL to UTF8. If you don't do this, your already UTF8-encoded PHP strings may get encoded again in the MySQL database. This leads to a problem called double-encoding. Edit: although some answers recommend a SET NAMES, it is not recommended on the PHP documentation

  4. Have your database, table, and column charsets all be utf8. I think you already have this covered.

If you do all of this, your app should work fine with the normal PHP functions, although various libraries may screw things up.

phsource
Jk_
Hmm, from what I know about AS3, there might be an `escape($value);` statement being called somewhere in the AS3. A way to solve this is just to do a `urldecode($value);` on any input from the Flash before sending it to the database. *Edit:* note that this may mess up + signs, as urldecode converts them to spaces.
phsource