Complex Relational databases -Using PHP/MYSQL for databases

Interactive Databases 3 | Webdevonline Extra | Database Menu

Setting up a server based relational database

This is more complex but the end result is more flexible and powerful. You can connect online to most databases inclusing MYSQL and Access.

To create a database connection first you must decide if you you are going to set up a ASP, JSP, ColdFusion or PHP dynamic page to link to the database

This section deals with PHP and MySQL and concentrates on using Dreamweaver routines. To see about ASP linking to databases go to the separate ASP section

This section assumes that you have an MYSQL database set up on the server and that you have accessed it and entered data into it.

NB

In order to build these features you need a dynamic database connection called a 'testing server' This will always work OK so you will be able to build php and serverside pages: The connection to the remote mySQL server will not work unless you have the info correct when you set it up.

See the example below: Notice the url prefix has the www.address. Dreamweaver will put in the ftp address and you will not connect to the database unless you change it!





 


Setting up a PHP Dynamic Database Connection

Using Dreamweaver

(1) Set up the testing server on your local computer

Dreamweaver needs to set up a 'testing' connection to the server.

  • This is used to test that the connections work and that the recordset and tables are properly set up and working.
  • This 'testing server' connection is usually the same as that given for the remote location that Dreamweaver uses to FTP to the server. (unless you set up local testing)
  • Go to Site/Edit Sites and select your site.

You should give the details as follows in 'Testing Server'

  • Server Model: PHPMySQL
  • Access: FTP
  • FTP Host: The ftp address of your site
  • Host Directory: the root for your site (can usually be left blank)
  • URL Address: the standard url for the root of your site used to access the Index Page

 

  • You should test your connect to your site through the 'Testing Server'

(2) Connect to your database on your server

This is done by using the Application Panel (Databases Panel in MX)

  • Open the Application Panel
  • Click the + button to create a MySQL connection.
  • The dialogue box below opens. Your hosting company will have told you the connection details to fill in
  • The connection name is for your convenience to identify the name of the connection.
  • 'MySQL Server': - the address give by the hosting company to direct your dynamic page to the on line database. (this is usually localhost)
  • Username: - that used for the database. This may have been given a prefix by the server followed by an underscore eg webdev_cartadmin
  • Password: - Database password
  • Database: - the name of the database (often with prefix eg webdev_cartDB )
datapanel
  • Test the connection. You must be able to connect to the database on the server for the page to collect data from it.

(3) Construct a Recordset

You must first make the Recordset - this will determine what records you will see.
You will need to be online and connected to the database to establish it.

From DW Help:

'Recordsets serve as an intermediary between the database storing the content and the application server generating the page
The recordset itself is a collection of data retrieved from a specified database. It can include an entire database table, or a subset of the table’s rows and columns.
These rows and columns are retrieved by means of a database query that is defined in the recordset.'
The Recordset is the web page connection to the database.

 

  • Open up the Bindings Panel
  • Provided the 3 criteria are clicked and enabled you can proceed
  • Click the + button and the dialogue box below opens.
    The program automatically names the recordset, but you can rename it to prevent confusion.
    (Convention uses rrName....)
recordset

 

  • Click on Connection and select the database connection you have just successfully made!
  • If you click on Test the program will connect your web page to the database and fill in the details of the table. If All Columns is selected, all the database fields will appear.
  • This will then put the connection to the database onto your web page in a table when you click OK

NB This will select ALL the fields and records, indexed on the key field
If you want to see particular records you must specify a filter


Building the page

The database connection and recordset will not produce output on the screen.

To see your database a number of elements can be added from the Application tab on the Insert Bar

 

To continue go to: Interactive Databases 3