Accessibility

ColdFusion Article

 

Connecting to a database with ColdFusion


Table of Contents

How ColdFusion fits into the picture

ColdFusion is an application server. An application server is software that runs on a server, works with the web server, and extends its capabilities. When the web server detects a page's CFM extension, it passes the page to ColdFusion for processing (see Figure 3).

How ColdFusion works

Figure 3. How ColdFusion works

At its most basic, ColdFusion development consists of one server that hosts the ColdFusion server, the web server, and the database. In the best of scenarios, however, the database resides on a separate server computer. Dreamweaver is one of the preferred editors for developing ColdFusion application pages (see Figure 4).

How Dreamweaver works with ColdFusion

Figure 4. How Dreamweaver works with ColdFusion

This basic configuration may work for very small applications created by one developer, but a true development system would include separate systems for development, testing, and production.

The ColdFusion Markup Language (CFML) is a tag-based language that the ColdFusion server processes. This language is similar to HTML, except that all ColdFusion tags begin with cf. CFML tags signal the ColdFusion application server to perform specific operations. Each tag identifies an operation, such as including a block of code from another file (<cfinclude>) or setting a variable (<cfset>). You can combine CFML tags and HTML tags on one dynamic web page.

ColdFusion provides a set of extensions that can be installed on top of Dreamweaver to support this new release more fully. You can install these extensions after you have installed ColdFusion by accessing the ColdFusion Administrator, choosing Resources on the top navigation, and selecting to install the ColdFusion Extensions for Dreamweaver under Additional Installers.

Exercise: Setting up a database connection in dreamweaver

  1. In Dreamweaver, open the MyColdFusion site you defined at the beginning of this article.
  2. Within Dreamweaver, select File > New.
  3. In the General tab of the New Document dialog box, select Dynamic Page in the Category list and then select ColdFusion in the Dynamic Page list.
  4. Click Create.
  5. On the Applications panel, select the Databases tab, and then click the plus (+) button (see Figure 5).

    Note: If you do not see a plus (+) button, the extensions have not yet been installed.

    Editing a database through the Databases tab in Dreamweaver

    Figure 5. Editing a database through the Databases tab in Dreamweaver

  6. Choose the data source type that you would like to create. In this case, choose Microsoft Access Connection (see Figure 6).

    Microsoft Access Connection

    Figure 6. Making a Microsoft Access Connection

  7. Enter MyDataSource in the CF Data Source Name text box.
  8. Enter C:\coldfusion8\wwwroot\MyColdFusion\MySource.mdb in the Database File text box.
  9. Click OK to add the new data source to the list. Refresh the tab if necessary (see Figure 7).

    Refreshing a database through the Databases tab in Dreamweaver

    Figure 7. Refreshing a database through the Databases tab in Dreamweaver

  10. Ensure that MyDataSource appears in the data source list.
  11. Save the page as MyColdFusionPage.cfm in the C:\coldfusion8\wwwroot\MyColdFusion\ path.