mysql| Data | Database Toss a while, finally the ASP and MySQL connection completed, feeling, close-up of this article with you 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 (you can also use 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.
<title> MySQL connection test </title>
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<body>
<%
Strconnection= "Dsn=mysqltest;
Driver={mysql ODBC 3.51 driver};
Server= fill in the server address; uid= username; pwd= password; database=mm "
' Connection string, DSN is the data source identifier we set
Note that driver we just mentioned when setting up a System DSN.
Set conn = Server.CreateObject ("Adodb.connection")
Conn.Open strconnection
sql = "SELECT * from my" SQL query statement
Set rs = conn.execute (SQL)
If not Rs.bof then
%>
<table width= "167" >
<tr>
<TD width= "", "<b> name </b> </td>
<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>
<%
Else
Response.Write ("Sorry, no data found.")
End If
Rs.close
Conn.close
Set conn = Nothing
Set rs = Nothing
%>
</body>