
ColdFusion MX 7 Getting Started Experience Tutorial Page 30 of 47
stripped out of the HTML page so that the browser never sees any ColdFusion code. For an overview of how ColdFusion
interacts with the server and browser environments, see the ColdFusion and Dreamweaver Development Overview
animations section of the ColdFusion MX 7 Getting Started Experience.
Learning Point: What ColdFusion processes
ColdFusion ignores all HTML or text in your pages and only processes CFML tags, functions and variables.
1. Ensure that the index.cfm file is open in Code view.
2. ColdFusion MX 7 ignored the SQL statement you placed at the top of the index.cfm page, because it assumed that it
is just plain text that you wanted to display on the page. You must surround the SQL statement with the ColdFusion
cfquery tag to instruct ColdFusion to send the SQL statement to the database. Add the cfquery tags around the
SQL statements as the following code shows:
<cfquery name="artwork" datasource="cftutorial">
SELECT FIRSTNAME, LASTNAME, ARTNAME, DESCRIPTION, PRICE, LARGEIMAGE, ISSOLD, MEDIATYPE
FROM ARTISTS, ART, MEDIA
WHERE ARTISTS.ARTISTID = ART.ARTISTID
AND ART.MEDIAID = MEDIA.MEDIAID
</cfquery>
Learning Point: Using cfquery to access the database
When ColdFusion MX 7 processes this index.cfm page and encounters the cfquery tag, it passes the SQL statement to
the appropriate database for processing.
The database that it will communicate with is referenced through the datasource argument of the cfquery tag. In the
tutorial example, this is the cftutorial data source. Recall that in Step 5 of this tutorial, you associated the
cftutorial data source with the Microsoft Access cftutorial.mdb. That means that anytime you want ColdFusion to talk
to that database, you just need to reference the data source by name.
ColdFusion passes the SQL statement that is between the cfquery tags to the data source listed in the datasource
attribute. In the case of the SELECT statement, you expect that data to be returned. But where will that data be stored?
You also use the name attribute of the cfquery tag. You use it to create and name a variable to store all of the data
retrieved from the database. You can think of it as a container sitting in the ColdFusion server’s memory to hold all of the
data. This is also referred to as a result set or query.
3. Save the index.cfm page and view it in the browser. (The SQL statement no longer displays on the page.)
Learning Point: Always save your ColdFusion pages
When using Dreamweaver to create HTML pages, you might have noticed that saving the page to view your changes is
not always required. This is not the case with ColdFusion pages. You must save them or your changes will not appear
when you browse your page.
4. Right-click on the background of the page and choose to view the source. The cfquery tags and the SQL statement
do not appear.
Commenti su questo manuale