开发者

Why are foreign characters saving to MySQL server in a funky way?

I send up the following to my PHP page, which then calls my MySQL server:

ethan•test•again

but for some reason it gets saved to the database as this:

ethan•test•again

Here is the some partial code in my PHP page that shows me saving the data:

if(mysql_query("开发者_StackOverflow社区CALL InsertTitle
(
  '".mysql_real_escape_string(urldecode($_POST['title']))."'
)"))

The interesting thing is that when I call the MySQL server to show the data via another PHP page, it appears just fine. Everything actually works just fine and as expected for me. Here is some sample partial code to pull from the data:

$result = mysql_query("SELECT title FROM item WHERE id = '".mysql_real_escape_string($_GET['id'])."'");

print "<?xml version=\"1.0\" encoding=\"UTF-8\"?><rss version=\"2.0\"><channel><title>Titles</title>";

while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) 
{
  echo "<title>".$row{'title'}."</title>";
}

And it appears just fine on the XML page:

ethan•test•again

Why does it look so funky in my MySQL server? Am I doing something wrong?


Use utf8_general_ci collation in your string table fields and add mysql_query("SET NAMES 'UTF8'"); after connecting to DB.


End and end looks fine, its something in the middle. I get the feeling its just the display that doesn't support the characters. Where are you looking at the database? If its console or phpmyadmin, i don't think it would display correctly, even though its saved in utf8.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜