用PHP保存日语字符

时间:2012-02-22 13:13:32

标签: php mysql utf-8

我目前正在尝试用PHP保存日语字符串。字符保存为问号。这是我的问题:

mysql_query("SET NAMES 'utf8'");
mysql_query("SET CHARACTER SET 'utf8'");

$result = mysql_query("INSERT INTO battles (basic_words) VALUES ('".mysql_real_escape_string($basic_words)."'");

字符串“$ basic_words”肯定包含日文字符但不保存。行“basic_words”的联盟 utf8_general_ci

1 个答案:

答案 0 :(得分:3)

php mysql query encoding problem建议

$db_con= mysql_connect('localhost', 'user', 'password');
if( function_exists('mysql_set_charset') ){
    mysql_set_charset('utf8', $db_con);
}else{
    mysql_query("SET NAMES 'utf8'", $db_con);
}

同时检查http://php.net/manual/en/function.mysql-set-charset.php