| "Allaire's Cold Fusion: It Can Make a Webmaster's Life Easier" Olga Verbeek, Salve Regina University | |
| September/October 2000 |
Introduction
Nuclear physics jokes aside, ColdFusion is a powerful Web development tool for creating interactive, database-driven Web solutions. With ColdFusion, you can dynamically serve Web pages and create cross-platform, dynamic Web applications that exchange information from databases, templates, files, and users. And it's all done with simple tags that look a lot like HTML. ColdFusion integrates Hypertext Markup Language (HTML), Extensible Markup Language (XML), Structured Query Language (SQL), databases, and ColdFusion's tag-based scripting language (CFML) to enable even the intermediate-level Web developer to create versatile, sophisticated Web sites.
ColdFusion is compatible with open standards and has integrated support for all Internet technologies, including Java, JavaScript, DHTML, and practically everything else. ColdFusion, proprietary software developed by the Allaire Corporation, is similar in functionality to Microsoft's Active Server Pages (ASP), although its friendly tag-based markup language makes it faster and easier to get started. If your site requires continuous updates, variations, daily news, events and the like, ColdFusion can save you immeasurable time. Developing with ColdFusion involves a relatively small learning curve, which helps to make it one of the fastest-growing Web technologies. The list of things you can do with ColdFusion is long, but its primary strength is that it enables users to search and select data from your databases, add records, perform transactions, customize the content of your site, and ! ! other such database-driven solutions.
Various ColdFusion Products
ColdFusion Server 4.5, the full version of ColdFusion, is on par with the most robust server applications out there. It has been designed to deliver top-notch performance from the smallest Access database on a basic server, to enterprise-level performance using multiple servers in tandem (clustering) and is available for Windows, Linux, Solaris, and the HP-UX operating systems.
ColdFusion Express is a freely available, pared-down version of ColdFusion. This program was used for the examples in this presentation.
ColdFusion Studio is tightly integrated with ColdFusion Server. ColdFusion Studio provides visual programming, database, and debugging tools for building sophisticated Web applications.
Some ColdFusion Basics
All ColdFusion documents must have a .cfm extension in order for the ColdFusion tags to work. The .cfm extension triggers the Web server to pass a request to the ColdFusion Application Server, which looks for and processes all ColdFusion operations before it returns a page. The ColdFusion Application Server is the software that runs on the Web server and handles all ColdFusion requests, processes them, and returns HTML and whatever other client-side technologies are present. In a nutshell, here's how it works:

ColdFusion and Databases
Perhaps the most important aspect of ColdFusion functionality is its relationship with databases. Instead of having to create HTML documents for every content component on a site, ColdFusion dynamically serves pages from content that resides in a database. ColdFusion can access databases using OLE DB and ODBC, and the full version includes native drivers for Oracle, Sybase, and other databases.
ColdFusion enables you to pass information from a database to the browser of a user connected to your site. This functionality enables you to create highly interactive, customizable sites. For example, you might want users to view a product catalog stored in a database. You might also want your product catalog sorted in a particular order so that the user can easily find information. To do this, you would create a ColdFusion page that extracts your product catalog from a database and displays the results, sorted in the order you chose, in the user's browser.
The page described above uses what's known as a query to pull the information from the database. To create a query in ColdFusion, you use SQL statements. SQL is an acronym for Structured Query Language, and is used to control, define, modify, and query data in a relational database.
In the ColdFusion .cfm page, SQL statements are contained within a CFQUERY block. The generic structure of a CFQUERY block is as follows:

Note that the CFQUERY tag has both a start and an end tag and that all SQL statements (in red) are contained within these tags. The opening CFQUERY tag also contains attributes. Two are required (NAME and DATASOURCE); one is optional (DBTYPE).
Although this is not a course on SQL, the most common and important SQL statement, the SELECT statement is shown in the above example. A SELECT statement must contain at least two clauses: the SELECT clause and the FROM clause. The SELECT clause specifies which database fields to query, while the FROM clause lists the tables where the fields are located. The WHERE clause is optional and allows setting up criteria to be met before a value is selected from the field.
You use the CFOUTPUT tag to output query results. You can also mix both HTML and CFML code within the CFOUTPUT block. Following is an example:

The QUERY attribute in the CFOUTPUT indicates which query is being displayed. In this example the values of field1 display in italics as indicated by the HTML tags.
ColdFusion and Headers & Footers
Other .cfm pages can be included within the current .cfm page using ColdFusionís CFINCLUDE tag. The format is as follows:

A common use of this feature is to put web site headers and footers which are the same across many of a web siteís pages into separate .cfm pages and then including them within the page as needed. Changes made within the included pages would automatically be propagated in the pages where they were included (similar to server-side includes).
ColdFusion and Forms
Forms are all over the Web, and for good reason -- they enable users to submit input. Forms in ColdFusion are set up the same as they are in any HTML document, but entail ColdFusion operations that turn an ordinary form into an application page, or collection of application pages. Non-ColdFusion forms involve scripts to make the form functional. With ColdFusion, relatively simple tags replace the need for scripts - the Application Server handles that. ColdFusion forms are most often used to enable users to add records to a database, customize pages, and perform searches and other common Web functions.
Trying it Yourself
If you wish to try this yourself you will need to install:
For the ColdFusion server to pass information back and forth between a database and an end-user, you must connect the database to the server. You do this through the administration tools found in the ColdFusion Administrator.
The ColdFusion Administrator was set up when you installed ColdFusion Express, and is accessed through the Start menu or through the ColdFusion 4.0 IDE Service icon in the System Tray (bottom right corner of the task bar). When you start the ColdFusion Administrator, your Web browser opens the administration page. This page (and the other pages that make up the Administrator) is located in the root directory of your Web server, in my case, C:\webshare\wwwroot.
You're now ready to connect your database to the ColdFusion server. Select the ODBC link from the menu on the main Administrator page. Once selected, the ODBC Data Sources Available to ColdFusion page is opened in the browser. It is through this page that you'll link any new database to the ColdFusion server. In addition, you use this page to set database parameters, such as giving the database a data source name and description.
The data source name you give a database will be referenced in your ColdFusion applications. For example, if you want to query data from the bookstore.mdb database, and you gave the bookstore.mdb database the data source name webbooks, your code would reference webbooks, not bookstore.mdb. Why would you give a database a different data source name than its filename? One reason is to give it a more logical, easy-to-understand name. On the other hand, you can stick with the original names.
More InformationÖ
ColdFusion Help and book sources from EZ Webdesign:
http://www.ezwebdesign.com/coldfusion.html
ColdFusion Tutorials from CFVault:
http://www.cfvault.com/index.cfm/mode/ContentPage/Element/tutorials_full_index
Very basic tutorials in ColdFusion from the Curry School Of Education,University of Virginia:
http://curry.edschool.virginia.edu/teacherlink/infotech/database/coldfusion/home.html
Olga Verbeek
Information Systems Librarian
McKillop Library
Salve Regina University
Newport, RI 02840
verbeeko@salve.edu
Comments Welcome!
© Copyright 1999-2001, ITIG ACRL/NEC Information Technology Interest Group. All Rights Reserved.
|
ACRL/NEC Home
|