UTF8中的Mysql数据库,PHP显示latin1(iso-8859-1) [英] Mysql database in UTF8, PHP shows latin1 (iso-8859-1)
问题描述
我已经转换了一个latin1数据库,我必须使用utf8。这个过程是:
#mysqldump -u root -p --default-character-set = latin1 -c --insert-ignore
- skip-set-charset mydb mydb.sql
#iconv -f ISO-8859-1 -t UTF-8 mydb.sql mydb_utf8.sql
[然后我将所有CHARSET = latin1替换为文件中的CHARSET = utf8,并且在编辑器中检查了
,查看非默认字符作为重音符号
正确使用UTF8 charset]
mysqlCREATE DATABASE mydb_utf8 CHARACTER SET utf8 COLLATE utf8_general_ci;
#mysql -u root -p --default-character-set = utf8 mydb_utf8< mydb_utf8.sql
我在PHP中创建了一个简单的脚本来从具有非
iso-8859-1编码中正确查看,而不是在UTF-8中查看。
此刻我一无所知问题在于。
..alex
Am Fri,2008年4月4日10:11:16 +0200 schrieb alex:
我在PHP中创建了一个简单的脚本来从具有非
iso-8859-1编码中正确查看,而不是在UTF-8中查看。
http: //dev.mysql.com/doc/refman/5.0/...onnection.html
我想使用set names utf8应该有所帮助。
Norbert
En / na Norbert Tretkowski ha escrit:
Am Fri,2008年4月4日10:11:16 +0200 schrieb alex:
>我在PHP中创建了一个简单的脚本来转储数据具有非标准字符的表格。但是生成的页面在
iso-8859-1编码中正确查看,而不是在UTF-8中查看。
http://dev.mysql.com/doc/refman/5.0/...onnection.html
我想使用set names utf8应该有帮助。
是的,它有帮助,但我为什么要更改我的应用程序?
我的意思是,如果数据库设置为utf8,表格也是utf8(并且
只是为了检查,我还设置在[client],[mysqld]和[server]下
值default_character_set = utf8),不应该把我的字符串作为
utf8返回给我吗?
这不是一点点错误吗? />
.. oO(alex)
> En / na Norbert Tretkowski ha escrit:
< blockquote class =post_quotes>
> Am Fri,2008年4月4日10:11:16 +0200 schrieb alex:
>> I在PHP中创建了一个简单的脚本来从具有非标准字符的表中转储数据。但是生成的页面在
iso-8859-1编码中正确查看,而不是在UTF-8中查看。
http://dev.mysql.com/doc/refman/5.0/...onnection.html
我想使用set names utf8"应该有帮助。
是的,它有帮助,但为什么我要更改我的应用程序?
我的意思是,如果数据库设置为utf8,表格是utf8也是(而且只是为了检查,我还在[client],[mysqld]和[server]下设置了
值default_character_set = utf8),不应该给php返回字符串作为
utf8?
这不是有点骚扰吗?
仅将数据存储为UTF-8是不够的。您还必须将MySQL和脚本之间的
连接设置为UTF-8,并且PHP必须将一个
正确的HTTP标头发送回浏览器。
Micha
I''ve converted a latin1 database I have to utf8. The process has been:
# mysqldump -u root -p --default-character-set=latin1 -c --insert-ignore
--skip-set-charset mydb mydb.sql
# iconv -f ISO-8859-1 -t UTF-8 mydb.sql mydb_utf8.sql
[then i replaced all CHARSET=latin1 to CHARSET=utf8 in the file, and
checked in the editor that non default characters as accents were viewed
correctly using UTF8 charset]
mysqlCREATE DATABASE mydb_utf8 CHARACTER SET utf8 COLLATE utf8_general_ci;
# mysql -u root -p --default-character-set=utf8 mydb_utf8 < mydb_utf8.sql
I made a simple script in PHP to dump data from tables which had non
standard characters. But the resulting page is viewed correctly in
iso-8859-1 encoding and not in UTF-8.
At this moment i''m clueless were the problem lies.
..alex
Am Fri, 04 Apr 2008 10:11:16 +0200 schrieb alex:I made a simple script in PHP to dump data from tables which had non
standard characters. But the resulting page is viewed correctly in
iso-8859-1 encoding and not in UTF-8.http://dev.mysql.com/doc/refman/5.0/...onnection.html
I guess using "set names utf8" should help.
Norbert
En/na Norbert Tretkowski ha escrit:Am Fri, 04 Apr 2008 10:11:16 +0200 schrieb alex:>I made a simple script in PHP to dump data from tables which had non
standard characters. But the resulting page is viewed correctly in
iso-8859-1 encoding and not in UTF-8.
http://dev.mysql.com/doc/refman/5.0/...onnection.html
I guess using "set names utf8" should help.
Yes, it helps, but why should i change my app?
I mean, if the database is set to utf8, the tables are utf8 too (and
just to check, i''ve also set under [client], [mysqld] and [server] the
value default_character_set=utf8), shouldn''t php return me the string as
utf8?
Isn''t this a bit bugged?
..oO(alex)
>En/na Norbert Tretkowski ha escrit:>Am Fri, 04 Apr 2008 10:11:16 +0200 schrieb alex:>>I made a simple script in PHP to dump data from tables which had non
standard characters. But the resulting page is viewed correctly in
iso-8859-1 encoding and not in UTF-8.
http://dev.mysql.com/doc/refman/5.0/...onnection.html
I guess using "set names utf8" should help.
Yes, it helps, but why should i change my app?
I mean, if the database is set to utf8, the tables are utf8 too (and
just to check, i''ve also set under [client], [mysqld] and [server] the
value default_character_set=utf8), shouldn''t php return me the string as
utf8?
Isn''t this a bit bugged?Just storing the data as UTF-8 is not enough. You also have to set the
connection between MySQL and your script to UTF-8 and PHP has to send a
correct HTTP header back to the browser.
Micha
这篇关于UTF8中的Mysql数据库,PHP显示latin1(iso-8859-1)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!