Database Reference
In-Depth Information
<HTML>
<TITLE>Asp MySQL MyODBC connection</TITLE>
<BODY>
This just defines the page as HTML for the browser and sets the page title to be dis-
played. Now for some ASP, as signified by the <%:
<%
set MyODBCConnection = Server.CreateObject(“ADODB.Connection”)
This creates an object that allows for a connection to a database and calls it
MyODBCConnection . This object can be used elsewhere by sending it commands by
appending them to the name of the object. We see this in use further down the page. Next
we define another object that handles sets of records using the following:
set MyRecordSet = Server.CreateObject(“ADODB.Recordset”)
This time we have called the object MyRecordSet . Now we have created two objects
needed for the connection to the database, we can start sending commands to them. The
first of these commands connects to the MyTestDataSource by sending the open command
to the MyODBCConnection object:
MyODBCConnection.Open “DSN=MyTestDataSource”
Now that this is open, we can connect our RecordSet object to the open data source:
MyRecordSet.ActiveConnection = MyODBCConnection
Then finally in this part of the ASP script, we can actually send an SQL command to the
data source with:
MyRecordSet.Open “SELECT * FROM user WHERE user='mafiu'”
%>
This page will create a table that has a row for every row returned from the query. We do
this by looping through the rows returned by the record set in ASP. However, we only want
the loop to run on the rows of the table itself, so the actual definition of the table is outside
the loop, in standard HTML as follows:
<TABLE border=1>
Now for the loop. For each row of the table we want to output an HTML table row as fol-
lows:
<TR><TD>Host column</TD><TD>User column</TD></TR>
Search WWH ::




Custom Search