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 (4) [RSS]
Blog Design (1) [RSS]
CFProject Scripts (2) [RSS]
Coldfusion Charts (3) [RSS]
Coldfusion Functions (5) [RSS]
Coldfusion Overview (1) [RSS]
Coldfusion Tutorials (16) [RSS]
For Sale (2) [RSS]
Image Manipulation (1) [RSS]
Java (1) [RSS]
JavaScript (4) [RSS]
PHP (1) [RSS]
Railo (4) [RSS]
SQL (1) [RSS]
Useful Tools (3) [RSS]

Recent Comments

Simple Coldfusion Upload Script
Alban said: Here is the error I get on the cffile line: String index out of range: -1 [More]

Coldfusion 8 Functions
Mark said: Can Cold Fusion do math functions similar to say Excel? I need to make several calculations, and if ... [More]

BlogCFC on Railo
iphone clone said: Thanks for sharing [More]

Coldfusion Protx VSP Form Integration Kit
confinedspace said: @Dom: Cheers for that - helped me out. Just one thing to note, I would add "all" as a thir... [More]

Coldfusion to PHP?
Jonny Shaw said: PHP is very similar to most other OOP languages, which i am quite familiar with, so it wasn't really... [More]

Recent Entries

No recent entries.
ColdFusion Blog | ColdFusion Hosting | ColdFusion Q & A