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:
MySQL4.0ForRadHatLinux (can also use forwindows) Windows2003standardEditionWindowsXPEnglish
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{mysqlodbc3.51driver} parameter on the right should be used as the ConnectionString for the ASP and database connection word for it.
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 MySQLODBC3.51Driver. Press "End".
At this time, a configuration dialog box will pop up:
DataSourceName Data Source Name: The identifier of the DSN used in the program can be named at will.
Host/ServerName (orIP) host/server name (or IP address), if it is localhost, fill in localhost
DatabaseName DatabaseName: 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.
Program code
<html>
<head>
<title>MySQL connection test</title>
<metahttp-equiv="Content-Type"content="text/html;charset=gb2312">
</head>
<body>
<%
strconnection="dsn=The name of the system DSN; driver={MYSQLODBC3.51driver}; server=server IP address;uid=user name for connecting to the database;pwd=password;database=database name"
'lybykwtestfor 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.