When using asp to read the MYSQL database, garbled characters appear. Are all the Chinese characters read? ? ? ? This problem is because
The database character set, table character set, and field character set are all set to: gbk_chinese_ci
Pay attention to Stmt=Set Names 'GBK' in the database connection string. This sentence must be included.
The following is the code for asp link to mysql. Please note that there is a GBK at the back. This specifies the encoding type of the link. Based on the data you use
Library encoding type. Modify it to your own.
ConnectionString =Driver={MySQL ODBC 3.51
Driver};Server=myserver;Database=mysql;User=myuser;password=mypassword;Option=3;Stmt=Set
Names 'GBK'
If you use a higher version of mysql, this situation often occurs. Chinese characters are often garbled; included in php.
Reference method:
Set the font of mysql.
Add in mysql.ini
[mysql]
default-character-set=gb2312
[client]
default-character-set=gb2312
[mysqld]
default-character-set=gb2312 //or gbk
After the registration is changed, the database before the change has no effect. The contents of the db.opt files in these database directories are changed to
default-character-set=gb2312
default-collation=gb2312_chinese_ci
You can also do this
dim driverName,chs
driverName=Driver={mysql odbc 3.51
driver};server=localhost;database=test;uid=loaer;pwd=123456;
set conn=server.createobject(adodb.connection)
conn.open driverName
'Execute the following sentence before querying
set chs=conn.Execute(SET NAMES 'gb2312')
'Query database table
sql = SELECT * FROM tb_commondata
Set rs = conn.Execute(sql)
This way there won't be garbled characters