Querying a Database Using Coldfusion

A simple coldfusion tutorial which explains how to query a database using coldfusion.

Querying a database in coldfusion is similar to other programming languages. The query is usually placed at the top of the page, or before where it is used.

The query is as below with an opening <cfquery> tag with the name of the query and the datasource that you are querying. Between the opening and closing <cfquery> tags you insert your sql code.

<cfquery name="queryname" datasource="datasourcename">
SELECT *
FROM table
</cfquery>

To output your retrieved data into the page you need to use the <cfoutput> tag, this tag lets the coldfusion server know that you are going to be outputting dynamic data.

the out put is simple between <cfoutput> tags you use # surrounding the data, to call from your query you would use the script.

<cfoutput>#queryname.attribute#</cfoutput>

The output is structured by using the query name to select what table you are outputting from and then the attribute would be equal the the row in a database.

Related Blog Entries

Comments

Archives By Subject

Advertising (3) [RSS]
Blog Design (1) [RSS]
CFProject Scripts (2) [RSS]
Coldfusion Charts (3) [RSS]
Coldfusion Functions (5) [RSS]
Coldfusion Overview (1) [RSS]
Coldfusion Tutorials (17) [RSS]
For Sale (2) [RSS]
Image Manipulation (1) [RSS]
Java (1) [RSS]
JavaScript (4) [RSS]
PHP (1) [RSS]
Useful Tools (3) [RSS]

Recent Comments

Coldfusion and Java
Henry Ho said: I'm more interested in writing Groovy with CFGroovy. I think you may want to look into that as well... [More]

Coldfusion and Java
Jeremy P said: Since CF is build on Java, it's very easy/handy to use it. I recently had to "drop down"... [More]

Coldfusion and Java
Kumar said: Similarly to what Ben said, we have used Java objects in ColdFusion to perform certain tasks. Dan V... [More]

Coldfusion and Java
Ben Nadel said: I use Java objects in ColdFusion all the time. The CreateObject( "java" ) method makes it ... [More]

Coldfusion and Java
Steve Brownlee said: Yes, I can provide some advantages, but that's a large discussion. It can provide speed advantages ... [More]

Recent Entries

Coldfusion and Java
Coldfusion Hosting From £2.50
Coldfusion Blog | Coldfusion Hosting | About Me