UTF-8头痛访问mySQL/PHP [英] UTF-8 Headaches Access to mySQL/PHP
问题描述
我的mySQL数据库创建显示
My mySQL database create shows
CREATE DATABASE `foo` /*!40100 DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci */
mySQL字段排序规则显示utf8_unicode_ci
.
The mySQL field collation shows utf8_unicode_ci
.
Access导出将代码页指定为Unicode (UTF-8)
.
The Access export specifies a Code Page of Unicode (UTF-8)
.
导入查询为
LOAD DATA LOCAL INFILE '/home/foo/Snapshot/tblImages.txt' INTO TABLE `tblImages` CHARACTER SET utf8 FIELDS OPTIONALLY ENCLOSED BY '|' TERMINATED BY ';' LINES TERMINATED BY '\n';
在绘制页面PHP问题之前
Before drawing the page PHP issues
header('Content-Type: text/html; charset=utf-8');
在<head>
我有
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
如果我在Windows 7下的UltraEdit中打开Access导出的txt文件,则会看到正确的重音符号:
If I open the Access exported txt file in UltraEdit under Windows 7 I see correct accents:
地方政府专有计划(圣菲利普道芬大街1000号)
如果我在Linux下的mySQL监视器中查询数据,我会看到:
If I query the data in mySQL monitor under Linux I see:
市政当局的土地规划方案(圣菲利普道芬大街1000号)
当我将查询输出回显到浏览器时,我看到:
And when I echo the query output to a browser I see:
计划正确吗?地方法院所在地? (1000个Dauphine街角圣菲利普)
如果我以其他查询开头:
If I preface the other queries with:
SET NAMES utf8;
然后在Webkit浏览器中,我看到了:
我在这里想念什么?
推荐答案
通过向连接中添加以下查询,解决了该问题:
The issue was resolved by adding these queries to the connection:
mysql_query("SET collation_connection = utf8_unicode_ci");
mysql_query("SET NAMES utf8;");
然后调用utf8_encode()
包装输出.
在给出所有标头和Content-Type设置的情况下,不需要调用函数吗?
The function call ought not be needed given all of the headers and Content-Type settings...?
这篇关于UTF-8头痛访问mySQL/PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!