mysql插入日语问题,MySQL-从PHP插入日语-编码问题

I'm trying to insert some japanese words in a mysql table!

If I insert 'こんにちは' using phpMyAdmin, the word is displayed fine from phpMyAdmin.

But if I try to insert it through php, as follow:

mysql_connect($Host, $User, $Password);

mysql_select_db($Database);

$qry = "INSERT INTO table VALUES (0 , 'こんにちは')";

echo mysql_query($qry);

In phpMyAdmin i see "ã“ã‚“ã«ã¡ã¯" ... why?

And if I try to fetch from the database:

$arr = mysql_fetch_array(mysql_query("SELECT * FROM table where id = 1"));

echo $arr[1];

The browser shows nothing!!!

How can I solve?

Thank you in advance for your help!!!

~EDIT~

My database collation is setup to utf8_general_ci

~EDIT 2~

I don't need to display the output on an HTML page, but the japanese words are printed on a XML page whose encoding is setup to UTF-8.

$plist = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";

$plist .= ""-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n";

$plist .= "\n";

$plist .= "\n";

$plist .= "\t\n";

$plist .= "\t\ttest\n";

$plist .= "\t\t".$arr[1]."\n";

$plist .= "\t\n";

$plist .= "\n";

$plist .= "";

echo $plist;

the output of this code is:

test

So, there is no value for the key "test" ... what can I do? Thanks!

~ SOLVED ~

Problems solved using the function mysql_set_charset() after connecting to the database!

解决方案

try this before the insert query

mysql_query("SET NAMES utf8");

Also not sure if you set the proper charset of the database, and of the web page.

Charset in HTML Head section?

and/or something like

header( 'Content-Type: text/html; charset=utf-8' );

Followings will help you get more ideas how to do it .. if something doesnt work commment back.

check more here on SO

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值