I have a website hosted with GoDaddy, including MySQL database on the back end. The site is a Slovenian site, so special characters are used.
The website is built in classic ASP and I have all the pages created in Notepad++ where utf-8 encoding is used. At the top of every page I also have Session.CodePage=65001, Session.LCID=1060 and Response.Charset="utf-8". MySQL db and all the tables are also utf8 encoded.
If I look at the data directly in db through Workbench interface, everything is ok, including some special Slovenian characters I use, like: č
If I go to my website, the Slovenian characters are also printed just fine, including č
The only problem is, that on the same page, data retrived from MySQL is not coded correctly, so letter č becommes ?
What could be the problem and how to solve it?
First I thought it is the MySQL ODBC 3.51 Driver, which I use to connect to db. I have tried adding charset=utf8 to the connection string, but didn't work. I have also tried adding charset=ucs2 to the connection string, which is a tip I found on another website, but it didn't help either. GoDaddy is not supporting MySQL ODBC 5.1 Driver, which could be a solution.
I am running out of options, so please help.
Best Answer
You have a chance for Slovenian letters according to this mapping and an excerpt from Windows-1252 wiki article:
Here's the things to do:
Use UTF-8 (without BOM) encoded files against the possibility of contain hard-coded text. (✔ already done)
Specify UTF-8 for response charset with ASP on server-side or with meta tags on client-side. (✔ already done)
Tell the MySQL Server your commands are in charset utf-8, and you expect utf-8 encoded result sets. Add an initial statement to the connection string :
...;stmt=SET NAMES 'utf8';...
Set the Response.CodePage to 1252.
I've tested the following script and it works like a charm.
DDL: http://sqlfiddle.com/#!8/c2c35/1
ASP:
As a last remark:
When you need to apply html encoding to strings fetched from the database, you shouldn't use Server.HTMLEncode anymore due to Response.Codepage is 1252 on server-side and since Server.HTMLEncode is dependent context codepage this will cause gibberish outputs.
So you'll need to write your own html encoder to handle the case.