Experience of ASP in using MySQL database

Source: Internet
Author: User

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.

 
 
  1. REGEDIT4  
  2. [HKEY_LOCAL_MACHINESOFTWAREODBCODBCINST.INImyodbc driver]  
  3. "UsageCount"=dword:00000002  
  4. "Driver"="C:\WINDOWS\System\myodbc.dll"  
  5. "Setup"="C:\WINDOWS\System\myodbc.dll"  
  6. "SQLLevel"="1"  
  7. "FileUsage"="0"  
  8. "DriverODBCVer"="02.50"  
  9. "ConnectFunctions"="YYY"  
  10. "APILevel"="1"  
  11. "CpTimeout"="120"  
  12. [HKEY_LOCAL_MACHINESOFTWAREODBCODBCINST.INIODBC Drivers]  
  13. "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!

 
 
  1. <%  
  2. strConnection = "dsn=hc188;driver={myodbd driver};server=localhost;uid=root;pwd=;database=hc188" 
  3. Set adoDataConn = Server.CreateObject("ADODB.Connection")  
  4. adoDataConn.Open strConnection  
  5. strQuery = "SELECT * FROM user" 
  6. Set rs = adoDataConn.Execute(strQuery)  
  7. If Not rs.BOF Then  
  8. %>  
  9. <TABLE>  
  10. <TR>  
  11. <TD<b>username</b></TD>  
  12. <TD><b>password</b></TD>  
  13. </TR>  
  14. <%  
  15. Do While Not rs.EOF  
  16. %>  
  17. <TR>  
  18. <TD><%=rs("username")%></TD>  
  19. <TD><%=rs("password")%></TD>  
  20. </TR>  
  21. <%  
  22. rs.MoveNext  
  23. Loop  
  24. %>  
  25. </TABLE>  
  26. <%  
  27. Else  
  28. Response.Write("Sorry, no data found.")  
  29. End If  
  30. rs.Close  
  31. adoDataConn.Close  
  32. Set adoDataConn = Nothing 
  33. Set rsEmailData = Nothing 
  34. %>  

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:

 
 
  1. 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!


 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.