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.