This article mainly introduces ASP's guide to using MySQL database. I hope it will be helpful to you. Let's take a look together.
MYSQL database has become the preferred database for many websites because of its advantages such as short, convenient, fast and free. However, it is generally used to combine PHP + MYSQL to develop various dynamic pages. In fact, ASP can also use MYSQL database to develop dynamic pages. I have just learned how to edit it and dare not enjoy it alone, so I wrote this article for your reference.
My environment is WINDOWS98+PWS4.0+mysql-3.23.32-win+PHP4
Required software:
PWS4.0
mysql-3.23.32-win
myodbc-2.50.36-dll
Step 1: Install MYSQL
ODBD driver, copy the downloaded myodbd-2.50.46-dll file to the windows/system directory (windows2000 is winnt/system32) and create a new file with the extension reg (that is, the registry file), and add the following contents Copy to this file.
REGEDIT4
- [HKEY_LOCAL_MACHINE/SOFTWARE/ODBC/ODBCINST.INI/myodbcdriver]
- 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/ODBCDrivers]
- myodbcdriver=installed
After saving, double-click the file and register the above code into the WINDOWS registry.
If installed in Windows 2000, the values of Driver and Setup primary keys need to be changed accordingly, I don’t need to say more about it here. If successful, the myodbd driver item will be seen in the driver of the control panel/ODBD data source!
Step 2: Create ASP file link database
There are two methods here, one is to establish a system DSN in the ODBC data source. Later I found that if I don't build it, I can use MYSQL in ASP. The method will be preached below.
Open the Control Panel/ODBD data source, select the system DSN, and then add a new DSN. Select the driver for myodbd driver. A dialog box will appear for inputting mysql-related information.
Windows DSN name: The name of the DSN you want to create
Mysql Host (name or ip): The name or IP address of the Mysql server, usually fill in localhost
Mysql database name: The database is required to be used, and the database is established in the Mysql manager. Here we use an example. Database name: hc188
There is a data table: user The data table has two fields: username and password, and insert a few data at will.
user: The user name of the link database, I filled in the root super user
password: Link database user password, if not, you can not fill it out
Port(if not 3306): Mysql is on the server port, if not filled in, the default is 3306
SQL command on connect: Use the SQL command to link the database, this item can be ignored
After filling in, select OK to save.
The following links to the ASP code of the database!
- <%
- strConnection=dsn=hc188;driver={myodbddriver};server=localhost;uid=root;pwd=;database=hc188
- SetadoDataConn=Server.CreateObject(ADODB.Connection)
- adoDataConn.OpenstrConnection
- strQuery=SELECT*FROMuser
- Setrs=adoDataConn.Execute(strQuery)
- IfNotrs.BOFTThen
- %>
- <TABLE>
- <TR>
- <TD<b>username</b></TD>
- <TD><b>password</b></TD>
- </TR>
- <%
- DoWhileNotrs.EOF
- %>
- <TR>
- <TD><%=rs(username)%></TD>
- <TD><%=rs(password)%></TD>
- </TR>
- <%
- rs.MoveNext
- Loop
- %>
- </TABLE>
- <%
- Else
- Response.Write(Sorry,nodatafound.)
- EndIf
- rs.Close
- adoDataConn.Close
- SetadoDataConn=Nothing
- SetrsEmailData=Nothing
- %>
The second method: I have thought during use that if I don’t set up a system DSN, can I also use the MYSQL database? The result is OK.
The method is very simple. Change the second line of ASP code above to:
strconnection=DefaultDir=;Driver={myodbc driver};database=hc188
I was curiously finding that this method can be used without even needing a username or password. Is it a bug in MYSQL?
All of the above codes have been tested and passed!
I hope that through this article, the introduction of MYSQL and asp database usage methods can help you.