让ASP也可以连接MYSQL 
发布时间:2006-10-14 2:41:17   收集提供:gaoqian
本文前提是下载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>
<%
};
%>
...
 
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50