开发者

MYSQL accentuated characters é display as %E9

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 scri开发者_运维问答pt 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_


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜