Examining the ColdFusion Query

To briefly recap the principle behind queries, let's take a closer look at a query from Day 2. This one works with my database of Elvis trivia, specifically examining the table "movies".

Here's the code for that query section, as it will appear in a ColdFusion template:

<CFQUERY NAME="movies" DATASOURCE="elvis">
SELECT title, year, rating FROM movies WHERE title = 'Speedway'
</CFQUERY>

If I used that query section in a template page along with a simple <CFOUTPUT> section to present the results, the user would see something like Figure 5.1 in his browser.

Figure 5.1. Sample output from a query where title = 'Speedway'.

The SQL statement in this query directed ColdFusion to go to my database, look for the "movies" ...

Get Sams Teach Yourself ColdFusion® in 21 Days now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.