The following articles mainly describe the full introduction of ASP in using MySQL databases. ASP still accounts for the majority of MySQL database applications. If you use this technology, if you are curious, the following articles will unveil its mysteries.
MySQL (the best combination with PHP) databases have become the first choice for many websites with its advantages of short, convenient, fast, and free, however, PHP + MySQL (the best combination with PHP) is usually used to develop a variety of dynamic pages. In fact, ASP can also use MySQL (the best combination with PHP) the dynamic page of database development, I just learned and did not dare to exclusive, so I wrote this article for your reference.
My environment is Windows 98 + PWS4.0 + MySQL (the best combination with PHP)-3.23.32-win + PHP4
Necessary software: PWS4.0, nonsense)
MySQL (the best combination with PHP)-3.23.32-win: the latest version)
Myodbc-2.50.36-dll this is the most important, MySQL (the best combination with PHP) ODBC driver, can be downloaded to www. MySQL (the best combination with PHP). com)
Step 1: Install the ODBD driver for MySQL (the best combination with PHP)
Copy the downloaded myodbd-2.50.46-dll file to the windowssystem directory
Is winnt/system32) and then create a new file with the extension reg as the registry file), copy the following content to the file.
- REGEDIT4
- [HKEY_LOCAL_MACHINESOFTWAREODBCODBCINST.INImyodbc 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_MACHINESOFTWAREODBCODBCINST.INIODBC Drivers]
- "myodbc driver"="installed"
Double-click the file and register the above Code to the WINDOWS registry.
If it is installed in windows2000, the value of the Driver and Setup primary key must be changed accordingly. I don't want to say much here. If it succeeds, you will see the myodbd driver in the driver of the control panel/ODBD data source!
Step 2: Create an ASP file link database
There are two methods, one is to create a system DSN In the ODBC data source. Later, I found that MySQL (the best combination with PHP) can be used in ASP even if it is not created. The method will be described below.
Open Control Panel/ODBD data source, select system DSN, and add a new DSN. Select mydbd driver as the driver. A dialog box is displayed for you to enter MySQL (the best combination of MySQL and PHP) related information.
Windows DSN name: name of the DSN to be created
MySQL (the best combination with PHP) Host (name or ip): The name or ip address of the MySQL (the best combination with PHP) server.
MySQL (the best combination with PHP) database name: the name of the MySQL database must be used. The database is created in the MySQL (the best combination with PHP) management program. Here is an example. Database Name: hc188
There is a data table: the user data table has two fields: username and password. Just insert a few data.
User: the user name used to connect to the database. I entered the root Super user.
Password: password used to connect to the database. If not, leave it empty.
Port (if not 3306): the Port on the server where MySQL (the best combination with PHP) is located. if this parameter is left blank, the default value is 3306.
SQL command on connect: use SQL commands to connect to the MySQL database. This parameter is optional.
After entering the information, select OK to save.
The ASP code of 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
- %>
Method 2: I thought about using the MySQL database if the system DSN is not set up? The result is acceptable.
The method is very simple. Change the second line of the above ASP code:
- strconnection="DefaultDir=;Driver={myodbc driver};database=hc188"
I was surprised to find that this method can be used without the user name or password. Is it a BUG in MySQL (the best combination with PHP?
All the above Code has passed the test!