Wear this:
ALTER DATABASE `sua_base` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
It will only change your database to UTF8, and that does not define anything and does not solve anything, there are multiple types of charset and probably you have to see what is ideal for you, for example the most used are UTF-8 and Latin1 and within these 2 there are variations still in mysql, see more details on:
So first you must be sure which charset is what you want, if it is latin1 or utf8, for example if you want to use latin1 change the tables or the database with ALTER
will only change the encoding to something that may already conform to the encoding you want.
The problem of characters
Problems with characters like é
or �
occurs by bad configuration of the database up to your Asp (or php) scripts, then is not a mistake bank, but rather a misunderstanding of how to work with this.
If you will use UTF8 in the bank you must:
- Save ALL the scripts as UTF-8 NO GOOD
- Set the charset during connection to the bank
- Set the HTTP header in the request response such as Content-Type: text/html; charset=utf8
If you are going to use Latin1 in the bank you must:
- Save ALL the scripts as ANSI (or ISO-8859-1 or window-1252)
- Set the charset during connection to the bank
- Set the HTTP header in the request response, for example
Content-Type: text/html; charset=ISO-8859-1
(or Content-Type: text/html; charset=windows-1252
)
Attention, for it to work you must follow all the steps:
- Choose the encoding that will suit you best, latin1 or utf8
- Set the connection correctly
- Set http charset with the same desired charset
- Save all documents/script without exception that will use database data with the same encoding
Configuring UTF-8
You must save all ASP scripts (up to the ones you will use with <!--#include file="..."-->
) in utf-8 without "GOOD", you can use software like Sublimetext or Notepad++ to convert the files:
Using Notepad++:
Using Sublime Text:
Then you must set on the connection to use UTF8 using the command SET CHARACTER SET utf8
:
If already configured in the file my.ini
this may be expendable, but I would keep to avoid problems if someone edit the my.ini
Dim cnnSimple ' ADO connection
Dim rstSimple ' ADO recordset
Set cnnSimple = Server.CreateObject("ADODB.Connection")
cnnSimple.Open "DRIVER={MySQL ODBC 5.3 Unicode Driver};SERVER=[mySQL server];
DATABASE=[DBName];UID=[DBUser];PASSWORD=[DB Password];"
Set rstSimple = cnnSimple.Execute("SET CHARACTER SET utf8") 'Define o charset
Setting up latin1
First you must save "all scripts. Asp" as iso-8859-1 (or ANSI):
Then you must set on the connection to use UTF8 using the command SET CHARACTER SET latin1
:
If already configured in the file my.ini
this may be expendable, but I would keep to avoid problems if someone edit the my.ini
Dim cnnSimple ' ADO connection
Dim rstSimple ' ADO recordset
Set cnnSimple = Server.CreateObject("ADODB.Connection")
cnnSimple.Open "DRIVER={MySQL ODBC 5.3 Driver};SERVER=[mySQL server];
DATABASE=[DBName];UID=[DBUser];PASSWORD=[DB Password];"
Set rstSimple = cnnSimple.Execute("SET CHARACTER SET latin1") 'Define o charset
Setting the HTTP charset
You can do this in two ways, via HTML or via response
, follow:
Using UTF-8 in HTML
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
Using UTF-8 on response
that should go before any HTML content:
<%@Language=VBScript CodePage = 65001%>
<%
Response.charset ="utf-8"
Response.CodePage = 65001
%>
<html>
...
Using latin1 (iso-8859-1 or windows-1252) in HTML
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
Using UTF-8 on response
that should go before any HTML content:
<%@Language=VBScript CodePage = 65001%>
<%
Response.charset ="iso-8859-1" 'pode usar windows-1252 também
Response.CodePage = 28591
%>
<html>
...
Completion
If you have followed all of the steps correctly there will probably be no more failures, neither in the reading of the database nor in the recording of the data, all that was said in this answer is the same that I have explained in:
Your website is being developed in what language?
– gabrielfalieri
Gabriel is currently in ASP and soon until December 2018 I will migrate to PHP
– user2832991