让ASP也可以连接MYSQL
2000-12-12 10:15:36 来源:WEB开发网核心提示:本文前提是下载MySQLX 地址为http://www.amedea.cz/mysqlx/DownloadFiles/MySQLX.zip 这个工具其实是MYSQL的组件对象模块.同样它也支持Delphi, Visual Basic, Visual C++, C++ Builder等工具的调用.以下是在asp里的调用方
本文前提是下载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>
<%
};
%>
...
这个工具其实是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>
<%
};
%>
...
[]
更多精彩
赞助商链接