How ASP uses MySQL Database

Source: Internet
Author: User
Tags dsn ini odbc mysql mysql host mysql in mysql database mysql odbc driver
MySQL database with its short, convenient, fast, free and so on the advantages of becoming a lot of web site at present preferred database, but generally are combined with php+mysql to develop a variety of dynamic pages, in fact, ASP can also use the MySQL database development dynamic page, I have just learned, I do not dare to enjoy alone, So close-up of this article for everyone's reference.

My environment is WINDOWS98+PWS4.0+MYSQL-3.23.32-WIN+PHP4.

Necessary software: PWS4.0 (oh, nonsense)

Mysql-3.23.32-win (This is the latest edition)

Myodbc-2.50.36-dll (This is the most important, MYSQL ODBC driver that can be downloaded to www.mysql.com)

Step one: Install the 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, The extension is Reg (that is, the registry file), and the following content is copied 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" = "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 in the Windows registry.

If installed in Windows2000, then the value of the driver and the Setup primary key will be changed accordingly, and I don't want to say more.

If successful, you will see the MYODBD driver in the driver for the/ODBD data source in the Control Panel!

The second step: Establish ASP File link database.

Here are two ways to create a System DSN in an ODBC data source. Later I found that it was possible to use MySQL in ASP, and the method would be preached below.

Open the Control Panel/odbd the data source, select the System DSN, then add a new DSN, the driver chooses MYODBD driver, a dialog box appears for you to enter MySQL

Related information.

Windows DSN Name: The name of the DSN to be established

MySQL Host (name or IP): the name of the MySQL server or IP address, usually filled localhost

MySQL database name: You need to use the names of the databases, which are established in the MySQL management program. Here we use an example. Database name: hc188, there are data tables: The User Data table has two fields, respectively: username and password, insert a few data randomly.

User: The username of the linked database, I am the root superuser

Password: Link database user password, if not, can not fill

Port (if not 3306): MySQL on server ports, if not filled defaults to 3306


SQL command on Connect: Using SQL commands to link to a database that does not fill in

Select OK to save after completing the completion.

The following links the ASP code of the database!


<%
strconnection = "dsn=hc188;driver={myodbd driver};server=localhost;uid=root;pwd=;d atabase=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 but 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 approach: I thought about using the MySQL database if I didn't create a system DSN? The result is OK.

The method is simple, the second line of code for the above ASP code should read:

strconnection= "defaultdir=;D river={myodbc Driver};d atabase=hc188"

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

All the above code passed the test!

To this end of the full text, is not very simple! I hope I can help you!



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.