I connect to MySQL version 5.5.50-log from classic ASP pages.
The MySQL Database is set up as follows:
- Database charset: utf8mb4
- Database collation: utf8mb4_general_ci
The table and field:
- Character Set: utf8mb4
- Collation: utf8mb4_general_ci
To test, I have data in the table, which contains this string: (T_T) é, è, à, ç
This is a screenshot of the data from the SQLyog:
This is my test web page:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Test</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
</head>
<body>
<p>Pasted directly from database field: (T_T) é, è, à, ç</p>
<p>Returned from SQL statement: ?(T_T) é, è, à, ç</p>
</body>
</html>
The issue is not that emoji data cannot be displayed on the web page, as the directly pasted content from MySQL appears fine. The issue is that once the data is returned from an SQL Select from MySQL via the ODBC Driver, it does not render correctly.
I have the following set in the ASP code:
Response.CodePage = 65001
Response.CharSet = "utf-8"
I have tried other variations - e.g.
Response.CodePage = 1252
Response.LCID = 1060
Response.Charset = "utf-8"
But they made no difference.
I have tried a range of MySQL ODBC Drivers - e.g.
''----------------------
''connection string
''----------------------
Dim oConn
set oConn = Server.CreateObject("ADODB.Connection")
'oConn.Open "DRIVER={MySQL ODBC 5.1 Driver}; Server=localhost; Database=mydb; User=root; Password=testing; Option=3; CharSet=utf8mb4; stmt=SET NAMES 'utf8mb4';"
That doesn't work...
I have tried using a System DSN instead using these drivers:
- MySQL ODBC 5.1 Driver
- MySQL ODBC 8.0 Unicode Driver
- MySQL ODBC 8.0 ANSI Driver
None of them solve the issue.
I wondered if there is any way around this, or if there is basically no way to display emoji data that is retrieved from a MySQL database using Classic ASP?
As far as I know, from reading elsewhere, the MySQL database is set up correctly, in a way which supports storing emoji characters, confirmed by the fact I can view it stored in the database without an issue. It's just when I try and pull it out of the database via the Classic ASP to MySQL connection that the emoji character is not displayed.
Edit - the ASP page itself is saved as a UTF-8 encoded file: