Skip to Main Content
Programming ColdFusion MX, 2nd Edition
book

Programming ColdFusion MX, 2nd Edition

by Rob Brooks-Bilson
August 2003
Intermediate to advanced content levelIntermediate to advanced
1140 pages
68h 45m
English
O'Reilly Media, Inc.
Content preview from Programming ColdFusion MX, 2nd Edition

Introducing cfquery

The cfquery tag is the main tag used by ColdFusion to interact with databases. Using cfquery, you can pass any Structured Query Language (SQL) statement to a data source registered with the ColdFusion Administrator. The content of your SQL statements determines what action is performed against the data source. The next section provides a quick primer on SQL.

The cfquery tag works by establishing a connection with the specified data source, passing a series of SQL commands, and returning query variables that contain information about the operation. The basic syntax for using the cfquery tag is as follows:

<cfquery name="query_name"
         datasource="datasource_name">
SQL statements
</cfquery>

Each attribute in the opening cfquery tag specifies information about the data source and how ColdFusion should access it. The name attribute assigns a name to the query. Valid query names must begin with a letter and can contain only letters, numbers, and underscore characters. name is required when passing an SQL SELECT statement and is optional for all other SQL operations.[2] The datasource attribute is required in all circumstances except when dbtype is Query (covered later in Chapter 11) and specifies the name of the data source (as it appears in the ColdFusion Administrator) to connect to when executing the query. There are a number of additional attributes that can be used with the cfquery tag. For a complete list, see its tag reference in Appendix A.

[2] Although the ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Programming ColdFusion

Programming ColdFusion

Rob Brooks-Bilson

Publisher Resources

ISBN: 0596003803Supplemental ContentErrata Page