无法从数据库中获取要显示的正确字符
我正在重新设计一个网站,但现有数据库存在问题: 数据库排序规则设置为utf8_unicode_ci,在表行中我调用的排序规则似乎设置为latin1_swedish_ci,其中存储的字符是日语(但即使在phpmyadmin中)你也会看到其他字符(我猜是因为latin1_swedish_ci)。
当我打印查询结果时,我得到一堆 ???现在使用
mysql_query('SET NAMES utf8');
mysql_set_charset('utf8',$conn);
Will 输出 2009“N10Å'Ž” 2009?N10???2009“N11Å'Ž” 2009?N11???
有什么想法吗?
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);
Will output 2009â€N10ŒŽÂ†2009?N10???2009â€N11ŒŽÂ†2009?N11???
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
由于该表设置为使用 latin1_swedish_ci,因此无法正确存储输入的 UTF-8 数据。您需要切换该表以使用 utf8_unicode_ci 来处理未来的数据,但任何现有数据基本上都已损坏。切换排序后,您必须重新输入数据才能为现有记录获取正确的日语字符。
Because the table was set to use latin1_swedish_ci, it was unable to correctly store the UTF-8 data that was entered. You need to switch that table to use utf8_unicode_ci for data going forward, but any existing data is essentially corrupted. You would have to re-enter the data after switching the collate to get the correct Japanese characters for the existing records.
您需要将字符集更改为utf8。不需要更改排序规则即可显示日语字符(但为了能够对文本进行排序和比较,将其更改为 utf8_general_ci 可能是一个好主意)。
You need to change the charset to utf8. The collation do not need to be changed to display japanese characters (but to be able to sort and compare texts it might be a good idea to change it to utf8_general_ci).
大家好,感谢您的回复,这就是发生的事情,我无法真正更改数据库中的任何内容,因为该网站的另一个版本仍然使用该数据库并且将会启动。所以我找到的解决方案如下:
案例场景:
DB设置为使用UTF8 -> (utf8_general_ci) 但字段(至少是我需要的字段设置为 latin1_swedish_ci。
解决方案:
在 mysql_connect 之后,我输入以下内容:
然后在 PHP 文件中:
现在工作完美,字符以正确的日语显示。
我尝试了我能想到的所有其他解决方案,但没有运气(utf-8_decode/encode php 函数等..等等)
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:
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.
Solution:
After mysql_connect I put the following:
Then in the PHP file:
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..)