
410
DEVELOPING
COLDFUSION 9 APPLICATIONS
Accessing and Using Data
Las
t
upda
te
d 8/5/2010
<cftransaction>
<cfquery name="qInsEmp" datasource="cfdocexamples">
INSERT INTO Employees (FirstName,LastName,EMail,Phone,Department)
VALUES ('Simon', 'Horwith', 'SHORWITH','(202)-797-6570','Research and Development')
</cfquery>
<cfquery name="qGetID" datasource="cfdocexamples">
SELECT MAX(Emp_ID) AS New_Employee
FROM Employees
</cfquery>
</cftransaction>
Accessing and Retrieving Data
Several ColdFusion tags provide a way to retrieve data from a database and work with query data. Use the
cfquery
tag
to query a data source, the
cfoutput
tag to output the query results to a web page, and the
cfqueryparam
tag to help
reduce security risks in your applications.
Working with dynamic data
A web application page is different from a static web page because it can publish data dynamically. This can involve
querying databases, connecting to LDAP or mail servers, and leveraging COM, DCOM, CORBA, or Java objects to
retrieve, update, insert, and delete data at run time—as your users interact with pages in their browsers.
For ColdFusion developers, the term data source can refer to different types of structured content accessible locally or
across a network. You can query websites, LDAP servers, POP mail servers, and documents in a variety of formats.
Most commonly though, a database drives your applications, and for this discussion a
data source
means the entry
point from ColdFusion to a database.
Here, you build a query to retrieve data from the cfdocexamples data source.
To query a database, use:
•
ColdFusion data sources
•
The
cfquery
tag
•
SQL commands
Retrieving data
You can query databases to retrieve data at run time. The retrieved data, called the
recordset
, is stored on that page as
a query object. A
query object
is a special entity that contains the recordset values, plus RecordCount, CurrentRow,
ColumnList, SQL, Cached, and SQLParameter query variables. You specify the name of the query object in the
name
attribute of the
cfquery
tag. The query object is often called simply
the query
.
The following is a simple
cfquery
tag:
<cfquery name = "GetSals" datasource = "cfdocexamples">
SELECT * FROM Employee
ORDER BY LastName
</cfquery>
Содержание COLDFUSION 9
Страница 1: ...Developing Applications ADOBE COLDFUSION 9...