简体   繁体   中英

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. Everything just fine. If I write (an example) Response.Write("ĞŞÜÇÖİ") it works like a charm. But if that string comes from database, I see "ÄÅÜÇÖİ" instead of "ĞŞÜÇÖİ". When I look this with phpMyAdmin it's ok.

I use Dreamweaver CS6. I save all pages 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. I've written meta charset utf-8. I use ODBC 5.2 x64 driver and my connection string has charset:UTF8;. And all MySQL settings utf-8 (tables, fields, everything).

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; see the MySQL ODBC doco . eg add "charset=utf8;" "charset=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. However, since VBScript is running internally with UCS2, I gave it a try with charset=ucs2 and it works fine. 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. Job is done :)

Even your connection should be 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. 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. (For example, it indicates what character set to use for column values if you use a SELECT statement.)

A SET NAMES 'x' statement is equivalent to these three statements:

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

FYI: manual

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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