Arabic in MySQL

Here is how to read Arabic text from MySQL db from Classic ASP
I tried a lot of scenarios and googled a lot, and finally, this was working fine
Please pay attention to all details, since if one is not done correct, you will kiss Arabic chars bye bye.
Related to Arabic in MSSQL

Post image is using Bing AI too, you can tell because the Arabic and English characters are very bad.

CodeFunctionName
What is this?

Public

Tested

Original Work
- ASP files need to be saved as ANSI encodes, don't waste your time here, I tried it, ANSI is the one that works fine
- Use the Connections
    ConnString = "DRIVER={MySQL ODBC 3.51 Driver}; SERVER=" & ServerName & "; DATABASE=" & DBName_F & "; UID=" & UserName_F & ";PASSWORD=" & Password_F & "; OPTION=3"
- After connecting to DB, run these lines
    connection.execute "SET NAMES cp1256"
    connection.execute "set character set cp1256"
    You might see some issues with either ones based on the Driver version (on 3.51 both work fine), doing one of them should be enough
- Make sure that the Database in MySQL is in "utf8_general_ci" or "utf8_unicode_ci"
- Make sure that the table is in "utf8_general_ci" or "utf8_unicode_ci", using (DEFAULT CHARSET=utf8) in CREATE TABLE command
Example:
    SQL="CREATE TABLE names (Id int(10) unsigned NOT NULL auto_increment, Ename varchar(45) NOT NULL, " & _
        "Aname varchar(45) NOT NULL, Gender varchar(45) NOT NULL, Freq varchar(45) NOT NULL, " & _
        "Percent varchar(45) NOT NULL, PRIMARY KEY (Id)) ENGINE=InnoDB DEFAULT CHARSET=utf8;"
- Make sure the fields are in "utf8_general_ci" format also (which is the default settings once you create it in that format)
- Then just save the values into the MySQL database as regular INSERT command
- Enjoy and let me know


Other options :
Doing pages in Arabic - ASP + MySQL
1- All files should be saved in ANSI format, If one is in UTF-8 then it will not work
2- Add this in <Head > section
    < meta http-equiv="content-type" content="text/html; charset="windows-1256" >
3- Add these lines for connecting to database MySQL ODBC 3.51
    Connection.Open ConnString
    connection.execute "SET NAMES cp1256"
    connection.execute "set character set cp1256"
4- MySQL Database should be in UTF_UniCode_CI
    Table format should be UTF_UniCode_CI
    Field that holds arabic must be of 'Text' type, UTF_UniCode_CI
========================================== OLD =========================
Saving Arabic text in MySQL and read it in ASP
1- Database, Table, fields all should be UTF-8 Coallation utf8_unicode_ci
2- ASP fiels should be saved as ANSI (and not UTF8 or any other type) even if they include arabic strings
3- Add the meta
    < meta http-equiv="content-type" content="text/html; charset="windows-1256" >
4- After the connection statement, add these two lines
    connection.execute "SET NAMES cp1256"
    connection.execute "set character set cp1256"
5- No need to use this line at all
    < % @ codePage="1252" Language="VBScript" % >
6- No need to use the N'field_name' while saving data


Views 199

Downloads 33

CodeID
DB ID

ANmarAmdeen
602
Attachments
Revisions

v2.0

Wednesday
April
12
2023