Database Reference
In-Depth Information
may wish to try and use this file to access other data or queries to give yourself more expe-
rience.
In summary, you connect to a data source in ASP by:
Defining an ODBC Connection object.
Defining a Record Set object.
Opening the data source through the ODBC Connection Object.
Linking the Record Set to the ODBC Connection.
Sending the query to the database through the record set.
Processing the record set in a loop, outputting columns by name or by their index.
If you need to send a new query to the same connection, close the recordset and re-open
it with the new query.
ASP script is defined within an .asp file by surrounding it with <% … %>. Any other text
within the file is output directly as HTML.
The connection details described in this section are not specific to MySQL and
MyODBC; as long as you have the correct data source name and the same tables, this will
work with an ODBC data source from any database vendor.
MySQL and ColdFusion
Connecting to a data source in ColdFusion is done by using ColdFusion Markup Language
tags (CMFL) embedded within HTML code. When the ColdFusion server encounters CMFL
tags it processes the results and returns them as text to be send back to the webserver.
ColdFusion allows you to set up a data source remotely by using its remote administra-
tor website. Although we have already set up a data source using the Microsoft Control
Panel, we will demonstrate how you can do this through ColdFusion. The next section will
use ColdFusionMX running on localhost as a demonstration.
Creating a Data Source in ColdFusion
The ColdFusionMX administrator is accessed by pointing an internet browser at the fol-
lowing location:
http://localhost/CFIDE/Administrator
After entering your password, you are presented with a menu which has a Data Sources
link. Clicking on this will give you access to the data source setup page. Part of this page is
shown in Figure 14.10.
Type in the name of the data source you wish to create on the page shown in Figure
14.10. Then select the MySQL driver from the driver menu. Once selected, click the Add
button to take you to the page shown in Figure 14.11.
Figure 14.11 shows the dialogue that allows you to specify the details for the MyODBC
connection. You can fill this out using the same details and warnings that we used in the
section on setting up the data source with the Microsoft ODBC control panel. Once you
submit this form, the source is immediately tested by ColdFusion. If you get a page such as
Search WWH ::




Custom Search