Accessibility

Table of Contents

Setting up a ColdFusion development environment for Dreamweaver

Connect to a database

This section describes how to create a connection to a sample database.

The sample files you copied in the previous section include a sample Microsoft Access database file called tutorial.mdb. It also includes a SQL script called tutorial.sql that you can use to create a sample MySQL database. Because the Macintosh version of the ColdFusion server doesn't provide a native Microsoft Access database driver, Macintosh users can connect to the MySQL database. For instructions on creating the sample MySQL database, read my article, Setting up a PHP development environment for Dreamweaver, in the Dreamweaver Developer Center.

When developing a ColdFusion web application in Dreamweaver, you connect to a database by selecting a ColdFusion data source defined in ColdFusion Administrator, the server's management console.

A ColdFusion data source is a type of shortcut to a database. Dreamweaver uses the data source to create a connection to the database.

For information on connecting to other database systems, see Database connections for ColdFusion developers in Dreamweaver LiveDocs or Using Dreamweaver (Help > Dreamweaver Help).

Topics covered in this section:

Create a ColdFusion data source (Windows)

If you are running ColdFusion on a Windows machine, you can create a data source that points to the sample Microsoft Access database.

  1. In Dreamweaver, open one of the ColdFusion pages in your site, such as view.cfm or send.cfm.
  2. In the Databases panel (Window > Databases), click the Modify Data Sources button on the right side of the panel toolbar (the cylinder and pencil icon). Dreamweaver launches ColdFusion Administrator in a browser.
  3. Enter your ColdFusion Administrator password and click Login.
  4. Click the Data Sources link in the left sidebar.
  5. In the Data Source Name text box, enter connTownsend (no spaces).
  6. In the Driver pop-up menu, select Microsoft Access.
  7. Click Add.
  8. Click the Browse Server button next to the Database File text box, and then locate and select the tutorial.mdb database.

    Depending on where you copied the sample files in the previous section, the file should be located in the following folder:

    \ColdFusion8\wwwroot\MyWebApp\data\tutorial.mdb

  9. Click Submit to accept your choices and close the dialog box.

Create a ColdFusion data source (Macintosh)

If you're running ColdFusion on a Macintosh, you can connect to a MySQL database instead of the Microsoft Access database. Before completing this procedure, you must install MySQL and then create a sample database. For instructions on creating a sample MySQL database, see Setting up a PHP development environment for Dreamweaver in the Dreamweaver Developer Center.

After installing MySQL and creating the sample database, create a ColdFusion data source that points to your sample database. Make sure the MySQL server is started before completing the following procedure.

  1. In Dreamweaver, open one of the ColdFusion pages in your site, such as view.cfm or send.cfm.
  2. In the Databases panel (Window > Databases), click the Modify Data Sources button on the right side of the panel toolbar (the cylinder and pencil icon). Dreamweaver launches ColdFusion Administrator in a browser.
  3. Enter your ColdFusion Administrator password and click Login.
  4. Click the Data Sources link in the left sidebar.
  5. In the Data Source Name text box, enter connTownsend (no spaces).
  6. In the Driver pop-up menu, select MySQL (4/5).
  7. Click Add to define a data source for your MySQL database.
  8. Enter the following in the Database field: CafeTownsend. You created this database when you set up MySQL.
  9. Enter the following in the Server field: localhost.
  10. Enter the remaining settings:

    Username: your MySQL username

    Password: your MySQL password

    For example, if your MySQL user name (also known as an account name) and password are Kensei and Te22y3, enter the following values:

    Username: Kensei

    Password: Te22y3

    If you don't have a password, omit the password value as follows:

    Username: Kensei

    Password: <blank>

    If you didn't define a user name while configuring your MySQL installation, enter root as the user name, as follows:

    Username: root

    Password: <blank>

  11. Click Submit to create the new data source.

Create a connection in Dreamweaver

The final step of the setup process is to create a connection to the database.

For ColdFusion applications, Dreamweaver creates the connection automatically for you. Open any ColdFusion page in the Cafe Townsend site in Dreamweaver, and then open the Databases panel (Window > Databases). Your ColdFusion data source should appear as a database connection in the panel.

If the connection does not appear, click the Refresh button on the Databases panel toolbar, complete the checklist in the panel, or consult Troubleshooting database connections in Dreamweaver LiveDocs or Using Dreamweaver (Help > Dreamweaver Help).

In the Databases panel, expand the connTownsend branch, and then expand the Tables branch. Three tables should appear as in Figure 10.

Expanded tables in the Databases panel.

Figure 10. Expanded tables in the Databases panel.

Where to go from here

If you want, you can now proceed to the Developing a web application tutorial in the Dreamweaver Developer Center. This follow-up tutorial uses the setup described in this tutorial to teach you how to display dynamic content on web pages. The tutorial also shows you how to create a form that saves visitor comments to the database.