Creating your database connection in Dreamweaver is the final step in preparing your system for dynamic web development. Once this has been defined, you are ready to start producing dynamic websites. A PHP database connection tells Dreamweaver that the current site is going to create PHP pages and refer to a specific database to store or display data.
This tutorial shows you how to set up a PHP database connection from within Dreamweaver that you can then use for your site.
- A dynamic site defined in Dreamweaver
For instructions see Defining a Dynamic Site in Dreamweaver
- A MySQL database
The Databases panel allows you to define database connections for your site. This even gives you the opportunity to preview some of the data in your database once a connection is established.
Adobe removed the Databases panel from Dreamweaver CC so if you are using Dreamweaver CC or newer, you will need to first follow this tutorial
- From the Dreamweaver Window menu, select Databases.
The Databases Panel should now be open.
If the window doesn't appear, it is most likely tucked away in the tool panels along the right-hand side of Dreamweaver
Once the databases window is accessible, it's time to make a new connection.
If the databases window is grayed out and inactive, try creating a new, blank PHP page. (File > New...)
- In the database dialog, click the Add ( + ) option, then choose MySQL Connection.
The MySQL Connection window will display.
- In the Connection field, enter your connection name.
For this tutorial we will call our connection 'mysql_tutorial', but the connection name can be whatever you like. Try to keep it descriptive of the database being connected to, as several connections can get confusing to work with.
- In the MySQL server field, enter the name of your MySQL Server.
The MySQL server is the name of the server that hosts MySQL. In most cases, it will be hosted on the same server as your site, and in that case you can enter localhost as the server name.
- In the User name field, enter your user name and password.
User name is the name set up for the specific MySQL server you are connecting to, and Password is the password you defined when creating your database.
If you don't remember creating a password, you probably weren't asked to do so when setting up your testing server or database. You can leave this field blank, but should go and specify a password for your database later. For testing servers, your User name is probably 'root' as this is the default "SuperUser" for MySQL databases.
- In the Database field, enter your database or click Select to choose it from a list.
You can manually input the database here (including .sql), or click Select, to see a list of databases hosted on the MySQL server.
- Click Test to ensure that your database connection is working properly. A confirmation dialog should appear telling you it was succesful.
If the test was unsuccesful, this could be for a couple reasons:
- You entered something wrong in the Connection fields. Check that you entered everything correctly.
- Most hosting providers won't let you connect to your live database externally. In this case, your connection will probably be correct, but you won't be able to test it. Simply upload your files to your live server for testing in a browser.
You will not be able to use your live database when creating dynamic pages using WebAssist products such as DataAssist or eCart. These products need to be able to see your database and the tables within, in order to create the appropriate references. You will need to use your local testing server's database, and then export and import that database to your live server, when pushing your dynamic pages live.
- Once everything is entered correctly, click OK.
Dreamweaver creates a Connections folder in your current site. This folder will contain a file that includes the details for accessing your database. If you create additional database connections, a new file will be added to this same folder.
Confirm that this folder exists and contains the new connections file.
Now that your database connection is completely set up, you can now utilize it to create dynamic content for your site. Depending on what you intend to create, you might want to start using one of WebAssist's dynamic Dreamweaver extensions, such as DataAssist, eCart, or SecurityAssist.
With your database connection created, you are now ready to jump right into the Getting Started Guides for any of these products.