无法从数据库中显示正确的字符 [英] Can't get the right characters to display from the database

查看:83
本文介绍了无法从数据库中显示正确的字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在重新设计一个网站,而现有数据库存在问题:
数据库整理设置为utf8_unicode_ci,在表行中,我称该整理设置为latin1_swedish_ci存储在其中的字符是日语的(即使在phpmyadmin中也是如此),您还会看到其他字符(我想是因为latin1_swedish_ci)。

I'm re-designing a Web site and I have a problem with the existing data base: The database collate is set to utf8_unicode_ci and in the table row I'm calling the collate seems to be set to latin1_swedish_ci the characters store in it are Japanese (but even in phpmyadmin) you see other characters (I guess because of the latin1_swedish_ci).

当我打印查询结果时我得到一堆???现在使用

When I print the result from the query I get a bunch of ??? now using

    mysql_query('SET NAMES utf8');
 mysql_set_charset('utf8',$conn); 

2009年的产出将是N10Å'Žâ€2009年?N10 ??? 2009的是?N11Å'Žâ€2009年?N11 ???

Will output 2009â€N10ŒŽÂ†2009?N10???2009â€N11ŒŽÂ†2009?N11???

有什么想法吗?

推荐答案

大家好感谢您的答复,这是发生的事情,我无法真正更改数据库中的任何内容,因为该站点的另一个版本仍在使用该数据库并且将会运行。因此,我找到的解决方案如下:

Hi all thanks for your reply's this is what happened, I couldn't really change anything in the DB since there's another version of the site that still uses that DB and will be up. So the solution I found was the following:

案例:
数据库设置为使用UTF8->(utf8_general_ci),但该字段(至少

Case scenario: The DB is set to use UTF8 -> (utf8_general_ci) but the field (at least the one's I needed where set to latin1_swedish_ci.

解决方案:
在mysql_connect之后,我输入以下内容:

Solution: After mysql_connect I put the following:

mysql_query("SET NAMES 'Shift_JIS'",$conn);
mysql_set_charset('Shift_JIS',$conn); 

然后在PHP文件中:

$titleJP = $row['titleJP'];
$titleJP = mb_convert_encoding($titleJP, "UTF-8", mb_detect_encoding($titleJP,"Shift_JIS,JIS,SJIS,eucjp-win"));

现在可以正确显示日语字符了。
我尝试了所有其他可以想到的解决方案没有运气(utf-8_decode /编码php函数等。等)。

Now that worked perfectly the characters are displayed in correct Japanese. I tried every other solution I could think of with no luck (utf-8_decode/encode php functions, etc.. etc..)

这篇关于无法从数据库中显示正确的字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆