ASP connection MySQL Database detailed implementation code _ application Skills

Source: Internet
Author: User
MySQL ODBC 3.51 Drive http://www.jb51.net/softs/19910.html is required to enable ASP to connect to the MySQL database
Let's look at the code below.

Copy Code code as follows:

Set conn = Server.CreateObject ("Adodb.connection")
Conn.Open "Driver={mysql ODBC 3.51 DRIVER}; Server=127.0.0.1;database=shops; User=root; password=xxx; "

The code above is the core part.

Server connection servers such as 127.0.0.1
Database shops to select
User Server logon username
PASSWORD Server login Password

Okay, here's a look at the example
Copy Code code as follows:

<%
' Test read the contents of the MySQL database
strconnection= "Driver={mysql ODBC 3.51 driver};d atabase=weste_net;server=localhost;uid=root;password="
' No need to configure DSN
Set adodataconn = Server.CreateObject ("Adodb.connection")
Adodataconn.open strconnection
strquery = "SELECT * FROM News"
Set rs = Adodataconn.execute (strquery)
If not Rs.bof then
%>
<table>
<tr>
<td<b> Serial Number </b></td>
<td><b> title </b></td>
</tr>
<%
Do as not rs.eof
%>
<tr>
<td><%=rs ("news_id")%></td>
<td><%=rs ("News_title")%></td>
</tr>
<%
Rs.movenext
Loop
%>
</table>
<%
Else
Response.Write ("no data.")
End If
Rs.close
Adodataconn.close
Set adodataconn = Nothing
Set rsemaildata = Nothing
%>

Note
I didn't set up the database code. If there are Chinese garbled can try

' Set client character encoding
Copy Code code as follows:

Conn.execute ("Set Names '" & Mychareset & "")

To solve
If you want to use a port other than 3306, we need to install MySQL ODBC database driver, after installation

Copy Code code as follows:

Conn.Open "Driver={mysql ODBC 3.51 DRIVER}; server=127.0.0.1; Port=3333;database=shops; User=root; password=xxx; "

is not a problem.

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.