让ASP也可以连接MYSQL
文章类别:
asp | 发表日期:2008-10-5 20:53:18
本文前提是下载MYSQLX 地址为http://www.amedea.cz/mysqlx/DownloadFiles/MySQLX.zip
这个工具其实是MYSQL的组件对象模块.同样它也支持Delphi, Visual Basic, Visual C++, C++ Builder等工具的调用.以下是在ASP里的调用方法.
正确安装MYSQLX之后.ASP即可用一下方法访问MYSQL
<%@ language="JavaScript" %>
...
<%
con = Server.CreateObject("MySQL.Connection");
con.Connect("localhost", "root", "", "MyDatabase", 3306, 0);
sql = "select FirstName, LastName from Customers";
if (!con.Query(sql))
Response.Write("ERROR: ".concat(con.ErrMsg()));
else
{
%>
<table>
<tr>
<td class="header">
First name
</td>
<td class="header">
Last name
</td>
</tr>
<%
rs = Server.Create("MySQL.RecordSet");
rs.Connection = con;
while (rs.Next())
{
%>
<tr>
<td class="row">
<%= rs["FirstName"] %>
</td>
<td class="row">
<%= rs["LastName"] %>
</td>
</tr>
<%
};
%>
</table>
<%
};
%>
...