Database Reference
In-Depth Information
It should be mentioned at this point that I am simply going to show how to connect to
the data source and process some of the data that is returned. These examples will barely
scratch the surface of using ASP and ColdFusion which are immensely powerful products
in their own right. If you wish to investigate these further, they are covered in other topics
published by Springer.
MySQL and ASP
There are several ways in which you can connect your ASP script to a MyODBC data source.
This section will show one way using the MyTestDataSource data source that we created
earlier in this chapter using VBSCRIPT.
A webpage that is going to be processed by ASP will reside somewhere in your web space
of your webserver and have the extension .asp, for example:
c:\inetpub\wwwroot\myexample.asp
To send this file to the ASP interpreter, it has to be requested through the webserver
using an internet browser by going to the following location:
http://localhost/myexample.asp
The .asp file is a collection of ASP code and HTML tags. Some of the ASP code will itself
output HTML code.
The following code, when executed through an ASP server, will connect to our data
source and output some of its data:
<% @LANGUAGE=”VBSCRIPT” %>
<HTML>
<TITLE>Asp MySQL MyODBC connection</TITLE>
<BODY>
<%
set MyODBCConnection = Server.CreateObject(“ADODB.Connection”)
set MyRecordSet = Server.CreateObject(“ADODB.Recordset”)
MyODBCConnection.Open “DSN=MyTestDataSource”
MyRecordSet.ActiveConnection = MyODBCConnection
MyRecordSet.Open “SELECT * FROM user WHERE user='mafiu'”
%>
<TABLE border=1>
<%
while not MyRecordSet.EOF
response.write “<TR><TD>” & MyRecordSet.fields(0) & “</TD><TD>” &
MyRecordSet.fields(1) & “</TD></TR>”
MyRecordSet.MoveNext
Search WWH ::




Custom Search