Making a Connection to Your Database


Now that you have all the pieces in placea Web server, an application server, a database driver, a DSN (if neededsee the previous section for details), and a databaseyou're ready to make a database connection in Dreamweaver. This section demonstrates how to create three types of database connections: an ASP server to an Access database, a ColdFusion server to an Access database, and a PHP server to a MySQL database.

For the first task, connecting to an Access database using ASP, you can use the DSN you created in the last section. For the ColdFusion/Access connection, you'll create a DSN in the ColdFusion Administrator; and for the PHP/MySQL connections, you don't need a DSN.

To connect to a database using ASP:

1.

Open Dreamweaver. If you haven't defined an ASP site in Dreamweaver, create one now. If you are using a local Web server (IIS), the path to the root folder is C:\Inetpub\wwwroot. Create your site directory in the wwwroot directory.

2.

In Dreamweaver, create an ASP page by choosing File > New > Dynamic Page > ASP JavaScript. Save it as test.asp.

3.

With the test.asp page open in Dreamweaver, open the Application panel group and select the Databases tab to display the Databases panel (Figure 4.35).

Figure 4.35. Use the Databases panel to set up your ASP database connection.


4.

Click the plus button and choose Data Source Name (DSN) (Figure 4.36).

Figure 4.36. Create an ASP database connection using a DSN.


The Data Source Name (DSN) dialog appears.

5.

In the Connection Name field, enter a name for this connection (Figure 4.37). Don't use any spaces or special characters in the name.

Figure 4.37. Use the DSN dialog to set up an ASP database connection.


6.

In the Data Source Name (DSN) dropdown list, select the DSN name from Step 5 in the preceding task.

7.

From the Dreamweaver Should Connect options, select the Using Local DSN radio button.

Now it's time to test your connection. If you're using IIS and you have other Web servers installed as Windows services, make sure these services are turned off before proceeding. You can turn the services off in the Services window by choosing Start > Control Panel > Administrative Tools, and double-clicking the Services Shortcut icon.

8.

Click Test. If the connection is successful, a message displays indicating this. Click OK to close the message box.

9.

On the Databases panel, the new connection name displays (Figure 4.38).

Figure 4.38. The name of the new ASP connection is listed in the Databases panel.


To connect to a data source using ColdFusion:

1.

Open Dreamweaver. If you haven't defined a ColdFusion site in Dreamweaver, create one now. If you are using a local Web server (IIS), the path to the root folder is C:\Inetpub\wwwroot; if you are using Apache, the path to the root folder is C:\Program Files\Apache Group\Apache\htdocs. Use the getting_started directory in the cfdocs directory within the root folder as your site root.

If you are using IIS, make sure the Apache service is stopped. If you are using Apache, make sure that IIS is stopped.

2.

In Dreamweaver, create a ColdFusion page by choosing File > New > Dynamic Page > ColdFusion. Save it as test.cfm.

3.

With the test.cfm page open in Dreamweaver, open the Application panel group and select the Databases tab to display the Databases panel (Figure 4.39).

Figure 4.39. Use the Databases panel to set up your ColdFusion data-source connection.


4.

On the Databases panel, click the Testing Server link. The ColdFusion Administrator URL dialog appears (Figure 4.40). Click the Test button to confirm the URL. A message displays to let you know whether the test was successful. If it was, click OK to close the message dialog, and then click OK in the ColdFusion Administrator URL dialog to close it.

Figure 4.40. Confirm the URL for the ColdFusion administrator in the ColdFusion Administrator URL dialog.


If a message appears saying that the test was not successful, check to see that the ColdFusion service is running. If you are using ColdFusion with Apache, make sure the Apache service is running (Start > Control Panel > Administrative Tools > Services). If you are using ColdFusion with IIS, make sure that IIS is running (Start > Control Panel >Administrative Tools > Internet Information Services). Once the ColdFusion service is running, return to the Databases panel and follow the instructions in the previous paragraph.

5.

On the Databases panel, click the RDS Login link. The Login to ColdFusion Remote Development Services (RDS) dialog appears. In the Password field, enter your RDS password, and click OK to close the window.

6.

On the Databases panel, click the Data Source link. The ColdFusion Administrator Login window opens in Internet Explorer. In the Password field, enter your ColdFusion password, and click Login. The ColdFusion Administrator appears.

7.

From the list on the left, choose Data & Services > Data Sources. The Datasources page appears. In the Data Source Name field, enter CompassTravel (Figure 4.41). From the Driver drop-down menu, choose Microsoft Access with Unicode. Click Add. The Microsoft Access with Unicode page appears (Figure 4.42).

Figure 4.41. Add a new ColdFusion data source on the Datasources page.


Figure 4.42. Browse to the database file you want to use for a data source.


8.

Click the Browse Server button to browse to the location of the database. Navigate to the getting_started directory (see Step 1). Choose the db directory, and then select the CompassTravel.mdb file. Click Submit.

9.

A message appears above the page title to say that the data source updated successfully, and the CompassTravel DSN is added to the Connected Data Sources list farther down on the same page (Figure 4.43). Click the Logout link at the top of the page and close Internet Explorer.

Figure 4.43. The new data source is added to the Connected Data Sources list.


10.

In Dreamweaver, open the Databases panel. The new connection has been added to the connection list (Figure 4.44).

Figure 4.44. The name of the new ColdFusion data source is listed in the Databases panel.


To connect to a database using PHP/MySQL:

1.

Open Dreamweaver. If you haven't defined a PHP site in Dreamweaver, create one now. If you are using Apache, the path to the root folder is C:\Program Files\Apache Group\Apache\htdocs. Create your site directory in the htdocs folder.

If you are using Apache, make sure that IIS is not running.

2.

In Dreamweaver, create a PHP page by choosing File > New > Dynamic Page > ASP JavaScript. Save it as connectionTest.php.

3.

With the connectionTest.php page open in Dreamweaver, open the Application panel group and click the Databases tab to display the Databases panel (Figure 4.45).

Figure 4.45. Use the Databases panel to set up your PHP/MySQL database connection.


4.

On the Databases panel, click the plus button, and choose MySQL Connection from the menu.

The MySQL Connection dialog appears.

5.

In the Connection Name field, enter a name for the connection (Figure 4.46). In the MySQL Server field, enter localhost. In the User Name field, enter root or your MySQL user name if you have changed it from root. In the Password field, enter your MySQL password. Click the Select button next to the Database field to view a list of available connections. The Select Database dialog appears, and the names of all available MySQL connections are listed (Figure 4.47). Choose a database, and click OK to close the dialog.

Figure 4.46. Use the MySQL Connection dialog to configure your MySQL database connection.


Figure 4.47. Select a MySQL database from the list in the Select Database dialog.


6.

In the MySQL Connection dialog, click the Test button to test your connection. A message displays to let you know whether the connection was made successfully. Click OK to close the message dialog, and then click OK to close the MySQL Connection dialog.

7.

In Dreamweaver, open the Databases panel. The new connection has been added to the connection list (Figure 4.48).

Figure 4.48. The name of the new PHP/MySQL database connection is listed in the Databases panel.





Macromedia Dreamweaver 8 Advanced for Windows and Macintosh. Visual Quickpro Guide
Macromedia Dreamweaver 8 Advanced for Windows and Macintosh: Visual QuickPro Guide
ISBN: 0321384024
EAN: 2147483647
Year: 2004
Pages: 129
Authors: Lucinda Dykes

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net