Welcome to our free ColdFusion MX tutorial. This tutorial is based on Webucator's Comprehensive ColdFusion Training course.

Contact Us or call 1-877-932-8228


ColdFusion has a special data type called query. Recordsets returned from a database are of this data type and are called "queries".

The <cfquery> tag is used to send queries to a database and to store the results returned in a query variable.

<cfquery> Attributes
Attribute Description
name Name of query.
datasource Name of data source.
dbtype Only possible value is "query". Used with query of queries.
username Overrides username set up in ColdFusion Administrator.
password Overrides password set up in ColdFusion Administrator.
maxrows Maximum number of rows to return in record set.
blockfactor Maximum rows to get at a time from server.
timeout Number of seconds that each action of a query is permitted to execute before returning an error.
cachedafter Date value specifying when to drop query from cache.
cachedwithin Timespan for which to hold query in cache.
debug Turns debugging display on or off.

The query object created by this tag has the following properties.

Query Properties
Property Description
currentRow Current record of the query being processed.
columnList Comma-delimited list of column names.
recordCount Number of records returned by query.
executionTime Time it took to execute query.

You can find out how long a query takes to process by reading the cfquery.executionTime variable.

This following example is very similar to the previous one, except that the valid username and password are not hardcoded in the script but instead are searched for in a database.

Code Sample:

               <cfif isDefined("FORM.submitted")>
	<cfquery name="logincheck" datasource="runners">
		SELECT FirstName, LastName, Email FROM Users
		WHERE email='#FORM.email#'
				AND password='#FORM.password#'
	<cfif logincheck.RecordCount>
		<cflocation url="index.cfm" addtoken="no">
---- C O D E   O M I T T E D ----


This tutorial is based on Webucator's Comprehensive ColdFusion Training Course. We also offer many other ColdFusion Training courses. Sign up today to get help from a live instructor.