To connect asp to a mysql database, you need to install the MySQL ODBC 3.51 driver http://www.jb51.net/softs/19910.html.
Let's take a look at the following code.
Copy codeThe Code is 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 above code is the core part.
SERVER connection SERVER, such as 127.0.0.1
Shops of the DATABASE to be selected
USER Server login Username
PASSWORD server logon PASSWORD
Now let's take a look at the instance.Copy codeThe Code is as follows: <%
'Test the reading content of the MySql database
Strconnection = "driver = {mysql odbc 3.51 driver}; database = 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.exe cute (strquery)
If not rs. bof then
%>
<Table>
<Tr>
<Td <B> serial number </B> </td>
<Td> <B> title </B> </td>
</Tr>
<%
Do while 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 the database encoding above. If there are Chinese garbled characters, try again.
'Set the client character encodingCopy codeThe Code is as follows: conn.exe cute ("set names '" & myChareSet &"'")
To solve
To use a port other than 3306, We need to install the Mysql ODBC database driver.
Copy codeThe Code is as follows: Conn. Open "DRIVER = {MySQL ODBC 3.51 Driver}; SERVER = 127.0.0.1; PORT = 3333; DATABASE = Shops; USER = root; PASSWORD = xxx ;"
There is no problem.