In the ASP to connect MySQL database, the best through the ODBC method _ application techniques

Source: Internet
Author: User
Tags dsn odbc odbc connection name database
Toss for a while, and finally the ASP and MySQL connection completed, feeling, close-up this article with everyone to share.
Check a lot of information, ASP and MySQL connection currently has two ways: one is the use of components, more famous is MYSQLX, but a pity to 99 dollars. Two is to use MYODBC to connect, let's look at the second way.
Platform for testing:
MySQL 4.0 for Radhat Linux (also available for Windows) Windows 2003 Standard Edition Windows XP 中文版
I. Installation of MYODBC
1. Visit the website www.mysql.com and download MYODBC, we are using the 3.51 version.
2. Install MYODBC to Windows
Run download back myodbc-3.51.06.exe (filename varies by version)
Ii. establishing an ODBC connection
Entering: Control Panel-ODBC data source
At this point, we can already see that there is already one item in the User DSN: Myodbc3-test, note that the Driver{mysql ODBC 3.51 driver on the right side of this argument will have to be in one word. As an ASP and database connection connection Word (conection String).
Add a "System DSN"
Select the System DSN column in the dialog box and press the Add button on the right. This will allow you to select a data source. Choose MySQL ODBC 3.51 Driver. Press "End".
A configuration dialog box pops up:
The data source name DataSource name: The identifier of the DSN used in the program, which can be arbitrarily named.
Host/server name (or IP) host/server name (or IP address), if this is the local to fill in the localhost
DB Name Database name: The name of the library you want to use in your program.
User User: Log in to MySQL using username, special note, root user due to security problems can only log on the computer, of course, users can modify the user table to remove this feature.
Password key: Password for login
Port ports: Use default values, preferably not, unless you are sure.
When all is set, press "test data source" to see that the screen shows a successful connection.
The configuration is all done!
Third, ASP and database connection
The following is my test, connection MySQL source code, the connection library name is mm, the table name is my, the table has two fields name and sex.
Copy Code code as follows:

<title>mysql Connectivity Test </title>
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<body>
<%
strconnection= "dsn= system DSN name; Driver={mysql ODBC 3.51 driver};server= server IP address; uid= connection database user name; pwd= password; database= database name"
' LYBYKW test for August 21, 2006 Monday 8:49:44
' Connection string, DSN is the data source identifier we set to note driver We just mentioned when we set up the System DSN.
Set conn = Server.CreateObject ("Adodb.connection")
Conn.Open strconnection
sql = "SELECT * FROM Test" SQL query statement
Set rs = conn.execute (SQL)
If not Rs.bof then
%>
<table width=600 border=1>
<tr>
&LT;TD width= "" ><b>name</b></td>
&LT;TD width= "" ><b>sex</b></td>
</tr>
<%
Do as not rs.eof
%>
<tr>
<td><%=rs ("name")%></td> <!--name field-->
<td><%=rs ("Sex")%></td> <!--sex field-->
</tr>
<%
Rs.movenext
Loop
%>
</table>
<%
Rs.close
Else
Response.Write ("Sorry, no data found.") ")
End If
Set rs = Nothing
Conn.close
Set conn = Nothing
%>
</body>

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.