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"
DBTYPE="dbtype"
CONNECTSTRING="connection_string">
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.[5]
The DATASOURCE attribute is required in all
circumstances except when DBTYPE is
Query or Dynamic and specifies
the name of the data source (as it appears in the ColdFusion
Administrator) to connect to when executing the query. The
DBTYPE attribute is optional and specifies the type of database driver to use when connecting to the data source. Possible ...
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.
Read now
Unlock full access