让ASP也可以连接MYSQL
类别: ASP教程
本文前提是下载MYSQLX,这个工具其实是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>
<%
};
%>
...
正确安装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>
<%
};
%>
...
- 上一篇: 创建弹出式“每日提示”窗口
- 下一篇: ASP文件操作--列出目录及文件
-= 资 源 教 程 =-
文 章 搜 索