The MYSQL database has become the preferred database for many websites due to its advantages of being short, convenient, fast, and free. However, PHP+MYSQL is generally used to develop various dynamic pages. In fact, ASP can also use the MYSQL database to develop dynamic pages. Brother I have just learned it and don’t dare to keep it to myself, so I wrote this article for everyone’s reference.
My environment is WINDOWS98+PWS4.0+mysql-3.23.32-win+PHP4
Necessary software: PWS4.0 (haha, nonsense)
mysql-3.23.32-win (this is the latest version)
myodbc-2.50.36-dll (this is the most important, the MYSQL ODBC driver, which can be downloaded from www.mysql.com)
Step 1: Install the MYSQL ODBD driver and copy the downloaded myodbd-2.50.46-dll file to the windows/system directory (windows2000
Winnt/system32) Then create a new file with the extension reg (that is, the registry file), and copy the following content into the file.
REGEDIT4
[HKEY_LOCAL_MACHINE/SOFTWARE/ODBC/ODBCINST.INI/myodbc driver]
UsageCount=dword:00000002
Driver=C://WINDOWS//System//myodbc.dll
Setup=C://WINDOWS//System//myodbc.dll
SQLLevel=1
FileUsage=0
DriverODBCVer=02.50
ConnectFunctions=YYY
APILevel=1
CpTimeout=120
[HKEY_LOCAL_MACHINE/SOFTWARE/ODBC/ODBCINST.INI/ODBC Drivers]
myodbc driver=installed
After saving, double-click the file to register the above code into the WINDOWS registry.
If installed in Windows 2000, the values of the Driver and Setup primary keys need to be changed accordingly. I think there is no need to say more here.
If successful, you will see the myodbd driver item in the driver of the control panel/ODBD data source!
Step 2: Establish an ASP file link database.
There are two methods here. One is to establish a system DSN in the ODBC data source. Later I discovered that I can use MYSQL in ASP without setting up it. The method will be explained below.
Open the control panel/ODBD data source, select the system DSN, then add a new DSN, select myodbd driver as the driver, and a dialog box will appear for entering mysql related information.
Windows DSN name: The name of the DSN to be created
Mysql Host (name or ip): The name or IP address of the Mysql server, usually fill in localhost
Mysql database name: The name of the database needs to be used. The database is created in the Mysql management program. Here we use an example. Database name: hc188
There is a data table inside: The user data table has two fields: username and password. Just insert some data.
user: The username to connect to the database. I filled in the root super user.
Password: Link database user password, if not available, you don’t need to fill it in
Port (if not 3306): Mysql server port, if not filled in, the default is 3306
SQL command on connect: Use sql command to connect to the database. This item does not need to be filled in.
After filling in, select OK to save.
The ASP code for the database is linked below!
<%
strConnection = dsn=hc188;driver={myodbd driver};server=localhost;uid=root;pwd=;database=hc188
Set adoDataConn = Server.CreateObject(ADODB.Connection)
adoDataConn.Open strConnection
strQuery = SELECT * FROM user
Set rs = adoDataConn.Execute(strQuery)
If Not rs.BOF Then
%>
<TABLE>
<TR>
<TD<b>username</b></TD>
<TD><b>password</b></TD>
</TR>
<%
Do While Not rs.EOF
%>
<TR>
<TD><%=rs(username)%></TD>
<TD><%=rs(password)%></TD>
</TR>
<%
rs.MoveNext
Loop
%>
</TABLE>
<%
Else
Response.Write(Sorry, no data found.)
End If
rs.Close
adoDataConn.Close
Set adoDataConn = Nothing
Set rsEmailData = Nothing
%>
The second method: I thought during use whether I can also use the MYSQL database without establishing a system DSN? The result is OK.
The method is very simple. Change the second line of the above ASP code to:
strconnection=DefaultDir=;Driver={myodbc driver};database=hc188
I found out strangely that this method can be used without even requiring a username and password. Is it a BUG in MYSQL?
All the above codes have been tested and passed!
This is the end of the article. Isn’t it very simple? Hope this helps!