System: win2003
Step 1: configure the ODBC Data Source
Create a DSN In the ODBC data source. The specific method is:
1. Open the ODBD data source in the control panel;
2. Select "system DSN" and add a new DSN driver;
3. select mysql odbc 3.51 driver. A dialog box is displayed for you to enter MySQL:
(1) Windows DSN name: name of the DSN to be created, that is, the name of the database;
(2) MySQL Host (name or ip): The name or ip address of the MySQL server. Generally, enter LocalHost;
(3) MySQL database name: the name of the database to be used.
4. Create a database in the MySQL management program.
(1) user: the user name used to connect to the database. Enter root Super User;
(2) password: password used to connect to the database. Optional;
(3) Port (if not 3306): MySQL Port on the server. Enter 3306 by default;
(4) SQL command on connect: use SQL commands to connect to the database. Optional.
After entering all the information, press OK to save.
Step 2: Compile the database link file
For example, there is a database discut, the data table cdb_posts, the field: Name subject (the program is as follows :)
<%
Dim driverName, chs
DriverName = "Driver = {mysql odbc 3.51 driver}; server = localhost; database = discuz; uid = root; pwd = ;"
Set conn = server. createobject ("adodb. connection ")
Conn. open driverName
'Execute the following sentence before querying. This sentence is the key to solving the problem of reading database garbled characters.
Set chs = conn. Execute ("set names 'gb2312 '")
'Query a table
Set rs = conn. Execute ("Select * FROM cdb_posts ")
If Not Rs. Eof Then
Do While Not rs. EOF
If Rs. Eof Or Rs. Bof Then Exit Do
Response. Write rs ("subject") & "<br>"
Rs. MoveNext
Loop
End If
Rs. Close
Set Rs = Nothing
%>