After a while of trouble, I finally completed the connection between ASP and MySQL. I have a thought, I will share this article with you.
After checking a lot of information, there are currently two ways to connect ASP and MySQL: one is to use components, which is more famous, MySQLX, but unfortunately it costs $99. The second is to use MyODBC to connect. Let’s take a look at the second method.
Test platform:
MySQL 4.0 For RadHat Linux (can also use for windows) Windows 2003 standard Edition Windows XP English
1. Install MyODBC
1. Visit the website www.mysql.com and download MyODBC. We are using version 3.51.
2. Install MyODBC into Windows
Run the downloaded MyODBC-3.51.06.exe (file name varies by version)
2. Establish an ODBC connection
Enter: Control Panel -》ODBC Data Source
At this time, we can already see that there is an existing one in the user DSN: myodbc3-test. Note that the Driver{mysql odbc 3.51 driver} parameter on the right should be used as the Connection String for the ASP and database connection word-for-length.
Add a "System DSN"
Select the "System DSN" column in the dialog box and press the "Add" button on the right. You will be asked to choose a data source at this time. Select MySQL ODBC 3.51 Driver. Press "End".
At this time, a configuration dialog box will pop up:
Data Source Name Data Source Name: The identifier of the DSN used in the program can be named at will.
Host/Server Name (or IP) host/server name (or IP address), if it is localhost, fill in localhost
Database Name Database Name: The library name you want to use in the program.
User User: Use the user name to log in to MySQL. Pay special attention to the root user can only log in on the local machine due to security issues. Of course, users can remove this function by modifying the user table.
Password key: login password
Port: Use the default value, it is best not to change it unless you are sure.
After all settings are set, press "Test Data Source" to see that the screen shows that the connection is successful.
All the configurations are done!
3. Connection between ASP and database
Below is the source code I have tested to connect to MySQL. The library name is mm, the table name is my, and there are two fields name and sex in the table.
The code copy is as follows:
<html>
<head>
<title>MySQL connection test</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<%
strconnection="dsn=The name of the system DSN; driver={MYSQL ODBC 3.51 driver}; server=server IP address;uid=user name for connecting to the database;pwd=password;database=database name"
'lybykw test for Monday, August 21, 2006 8:49:44
'Connection string, dsn is the data source identifier we set. Note that driver we mentioned just when setting up the system DSN.
set conn = server.createobject("adodb.connection")
conn.open strconnection
sql = "select * from test" 'SQL query statement
set rs = conn.execute(sql)
if not rs.bof then
%>
<table width=600 border=1>
<tr>
<td><b>name</b></td>