让ASP也可以连接MYSQL

80酷酷网    80kuku.com

  mysql这个工具其实是MYSQL的组件对象模块.同样它也支持Delphi, Visual Basic, Visual C++, C++ Builder等工具的调用.以下是在ASP里的调用方法.
正确安装MYSQLX之后.ASP即可用一下方法访问MYSQL

<% language="java script" %>
...
<%
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>
<%
};
%>
...

分享到
  • 微信分享
  • 新浪微博
  • QQ好友
  • QQ空间
点击: