简体   繁体   English

ASP,MySQL和UTF-8

[英]ASP, MySQL and UTF-8

First of all, I've read almost all topics about this. 首先,我已经阅读了几乎所有关于此的主题。 I've tried all advices but I couldn't solve this problem. 我已经尝试了所有的建议,但我无法解决这个问题。

Here is the thing. 这就是事情。 I use Classic ASP and MySQL for a project. 我将Classic ASP和MySQL用于项目。 Everything just fine. 一切都很好。 If I write (an example) Response.Write("ĞŞÜÇÖİ") it works like a charm. 如果我写(例子)Response.Write(“ĞŞÜÇÖİ”)它就像一个魅力。 But if that string comes from database, I see "ÄÅÜÇÖİ" instead of "ĞŞÜÇÖİ". 但如果该字符串来自数据库,我会看到“ÄÅÜÇÃÄ°”而不是“ĞŞÜÇÖİ”。 When I look this with phpMyAdmin it's ok. 当我用phpMyAdmin看这个时,没关系。

I use Dreamweaver CS6. 我使用Dreamweaver CS6。 I save all pages Unicode (UTF-8). 我保存所有页面Unicode(UTF-8)。 I've written Session.CodePage = 65001, Response.CodePage = 65001, Response.Charset = "utf-8" in an include file that every page has it at the top. 我在一个包含文件中写了Session.CodePage = 65001,Response.CodePage = 65001,Response.Charset =“utf-8”,每个页面都将它放在顶部。 I've written meta charset utf-8. 我写过meta charset utf-8。 I use ODBC 5.2 x64 driver and my connection string has charset:UTF8;. 我使用ODBC 5.2 x64驱动程序,我的连接字符串有charset:UTF8;。 And all MySQL settings utf-8 (tables, fields, everything). 并且所有MySQL设置都是utf-8(表格,字段,所有内容)。

Well I don't want to use other encodings, charsets. 好吧,我不想使用其他编码,字符集。 What am I doing doing wrong? 我做错了什么? It seems, it's about database. 看来,这是关于数据库的。 What is the problem? 问题是什么?

You need to specify the character set in the connection string using the charset parameter; 您需要使用charset参数在连接字符串中指定字符集; see the MySQL ODBC doco . 看到MySQL ODBC doco eg add "charset=utf8;" 例如,添加 “charset = utf8;” "charset=ucs2;" “字符集= UCS2;” to your connection string. 到您的连接字符串。

Edited: I finally got a chance to run a simple test harness on this, and it does indeed fail with charset=utf8. 编辑:我终于有机会在这上运行一个简单的测试工具,它确实失败了charset = utf8。 However, since VBScript is running internally with UCS2, I gave it a try with charset=ucs2 and it works fine. 但是,由于VBScript在内部运行UCS2,我尝试使用charset = ucs2,它运行正常。 NB: page is still set to send all output as UTF-8, it's just that VBScript is pulling data from an ODBC connection using UCS2. 注意:页面仍设置为以UTF-8发送所有输出,只是VBScript使用UCS2从ODBC连接中提取数据。 Job is done :) 工作完成了:)

Even your connection should be UTF8. 甚至你的连接应该是UTF8。 run this query before you run other queries 在运行其他查询之前运行此查询

set names 'utf8'

SET NAMES indicates what character set the client will use to send SQL statements to the server. SET NAMES指示客户端将用于将SQL语句发送到服务器的字符集。 Thus, SET NAMES 'cp1251' tells the server, “future incoming messages from this client are in character set cp1251.” It also specifies the character set that the server should use for sending results back to the client. 因此,SET NAMES'cp1251'告诉服务器,“来自此客户端的未来传入消息是字符集cp1251。”它还指定了服务器用于将结果发送回客户端的字符集。 (For example, it indicates what character set to use for column values if you use a SELECT statement.) (例如,如果使用SELECT语句,它指示要用于列值的字符集。)

A SET NAMES 'x' statement is equivalent to these three statements: SET NAMES'x'语句相当于这三个语句:

SET character_set_client = x;
SET character_set_results = x;
SET character_set_connection = x;

FYI: manual 仅供参考: 手动

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM