asp mysql数据库

asp连接mysql数据库的方法是什么

小亿
294
2023-10-08 11:53:53
栏目: 云计算

在ASP中连接MySQL数据库有多种方法,以下是常见的两种方法:

1. 使用ADODB连接对象(ActiveX Data Objects)

```asp
<%
Dim conn, rs
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "DRIVER={MySQL ODBC 8.0 Unicode Driver};SERVER=localhost;DATABASE=mydatabase;USER=username;PASSWORD=password;OPTION=3;"

Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open "SELECT * FROM tablename", conn

While Not rs.EOF
  Response.Write(rs("columnname") & "
")
  rs.MoveNext
Wend

rs.Close
Set rs = Nothing

conn.Close
Set conn = Nothing
%>
```

2. 使用MySQL Connector/ODBC驱动程序

```asp
<%
Dim conn, rs
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "DSN=mydsn;UID=username;PWD=password;"

Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open "SELECT * FROM tablename", conn

While Not rs.EOF
  Response.Write(rs("columnname") & "
")
  rs.MoveNext
Wend

rs.Close
Set rs = Nothing

conn.Close
Set conn = Nothing
%>
```

请注意,上述代码中的参数(如服务器地址、数据库名称、用户名、密码等)需要根据实际情况进行修改。

0
看了该问题的人还看了