ASP How to use MySQL Database

xiaoxiao2021-03-06  15

The mysql database has become the current preferred database of many websites in a short, convenient, speed, free and other advantages, but generally use PHP MySQL to develop various dynamic pages, in fact, ASP can also use the mysql database to develop dynamic pages, your younger brother I am also just learning, I don't dare to enjoy, so I close this article for everyone.

My environment is Windows98 PWS4.0 MYSQL-3.23.32-Win PHP4

The necessary software: PWS4.0 (huh, nonsense)

Mysql-3.23.32-win (this is the latest version)

Myodbc-2.50.36-dll (this is the most important, mysql odbc driver, you can download www.mysql.com)

Step 1: Install the mysql ODBD driver, copy the downloaded myodbd-2.50.46-dll file to the Windows / System directory (Windows2000 is Winnt / System32) and then create a new file, extension is REG (that is, registry File), copy the following to 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" = "02.50" "" "" "" "" "" "" "" "" "=" = "1" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" " 120 "[HKEY_LOCAL_MACHINS / SOFTWARE / ODBC / ODBCINST.INI / ODBC DRIVERS]" Myodbc Driver "=" installed "After saving, the above code is registered in the Windows Registry.

If installed in Windows2000, the value of Driver and Setup primary key should change accordingly, I don't have to say more here.

If successful, you will see the Myodbd Driver 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 found that I don't build, I can use MySQL in the ASP, and the method will take place below.

Turn on the control panel / ODBD data source, select the system DSN, then add a new DSN, the driver selects Myodbd Driver, a dialog box will appear for entering mysql

Related Information.

Windows DSN Name: The name of the DSN to establish

MySQL Host (Name or IP): The name of the MySQL server or IP address, usually fills Localhost

MySQL Database Name: The name of the database is required, and the database is established in the MySQL manager. Here we use an example. Database Name: HC188, there is a data table: USER Datasheets have two fields: username and password, plus several data.

User: Link database username, I fill in the root superuser password: link database user password, if not, you can not fill

Port (if not 3306): MySQL in the port of the server, if you don't fill it think 3306

SQL Command ON Connect: Use the SQL command to link the database, this can not fill

After filling, select OK.

The following links the database ASP code!

<% StrConnection = "dsn = hc188; driver = {myodbd driver}; server = localhost; uid = root; pwd =; database = hc188" Set adoDataConn = Server.CreateObject ( "ADODB.Connection") adoDataConn.Open strConnectionstrQuery = " Select * from user "set = adodataconn.execute (strquery) if not rs.BOF1%>

Username password < / b> <% do while not rEOF%>
<% = rs ("username")%> <% = rs ( "Password")%> <% rs.movenextLoop%> <% elseresponse.write ("sorry, no data firm.") end ifrs.closeadodataconn.closeset adodataconn = NothingSet RSemAildata = Nothing%> The second method: I think if I don't build the system DSN, can I use the mysql database? The result is possible.

The method is simple, and the second line of the ASP code is changed to:

StrConnection = "defaultdir =; driver = {myodbc driver}; database = hc188"

I am strange to find that this method can be used even if the username and password are needed. Is it a bug of MySQL?

All the above code is all tested!

At this point, the full text is over, is it very simple? I hope I can help you!

转载请注明原文地址:https://www.9cbs.com/read-48019.html

New Post(0)
CopyRight © 2020 All Rights Reserved
Processed: 0.095, SQL: 9