Presentation is loading. Please wait.

Presentation is loading. Please wait.

44238: Dynamic Web-site Development Working with a Remote Database Ian Perry Room:C48 Extension:7287

Similar presentations


Presentation on theme: "44238: Dynamic Web-site Development Working with a Remote Database Ian Perry Room:C48 Extension:7287"— Presentation transcript:

1 44238: Dynamic Web-site Development Working with a Remote Database Ian Perry Room:C48 Extension:7287 E-mail:I.P.Perry@hull.ac.uk http://itsy.co.uk/ac/0607/Sem1&2/44238_DWSD/

2 Ian Perry 44238: DWSD: Working with a Remote Database Slide 2 Why use a Remote Database?  To enable truly ‘dynamic’ content to appear on our Web-pages; especially if the same content, perhaps presented in a different order, and/or to a different level of detail, has to appear on multiple Web-pages.  The First Time Buyer Web-site (http://itsy.co.uk/ac/ftb/) has 5 Web-pages which display the same content;http://itsy.co.uk/ac/ftb/ the only ‘real’ difference being the order in which that data is presented.

3 Ian Perry 44238: DWSD: Working with a Remote Database Slide 3 What do we need?  A Remote Database: e.g. an Access Database; which has been populated with the data we wish to display in our Web-pages. which we then ftp to a Web Server, and set-up as an ODBC data source; with a data source name (DSN) ‘alias’ that can be used by server side programs in order to access this file.  AS-pages (containing VBScript), that can: open the remote database; using the DSN ‘alias’. apply an SQL query to the database; in order to build a temporary table of data (i.e. a record-set). then populate a Web-page; with named fields from this record-set.

4 Ian Perry 44238: DWSD: Working with a Remote Database Slide 4 The ‘Film List’ Web-site  Let us suppose that; we want to set-up Web-site that can display the details about a variety of Films, e.g.: Title, Date, Category, Description, Film Stars.  And; would like to be able to display these details in a variety of lists: sorted by Date and/or Category  And; would, ideally, like to be able to display: all of the films in which a particular Film Star has appeared.

5 Ian Perry 44238: DWSD: Working with a Remote Database Slide 5 An Access Database (i.e. film.mdb) Containing a single Table (i.e. list) NB. Should really have had at least two Tables, so we could store the names of more than TWO Film Stars?

6 Ian Perry 44238: DWSD: Working with a Remote Database Slide 6 The ‘list’ Table Is first populated with some test data. Then the.mdb file is ftp’d to the Web Server.

7 Ian Perry 44238: DWSD: Working with a Remote Database Slide 7 Need an ODBC Connection to the Remote Database  Open DataBase Connectivity (ODBC) A standard which specifies how databases from different software vendors, e.g. Oracle, MySQL, Access, etc. can communicate and exchange data with each other.  ODBC = Middleware ‘Translating’ between any ODBC compliant Database and any ODBC aware program that is attempting to access that Database.

8 Ian Perry 44238: DWSD: Working with a Remote Database Slide 8 Set-up ODBC Data Source - 1 Choose the ODBC Driver type (e.g. Access).

9 Ian Perry 44238: DWSD: Working with a Remote Database Slide 9 Set-up ODBC Data Source - 2 Choose the Name; i.e. the ‘alias’ by which you will refer to this Database within your program code. And; tell the server where the remote database is to be found.

10 Ian Perry 44238: DWSD: Working with a Remote Database Slide 10 Now for the Programming!  We need to: build the outline of an AS-page: That will display the data from the Database. open the remote database (i.e. film.mdb): using its DSN alias (i.e. filmlist). then, apply an SQL query to the database: in order to extract specific records (i.e. to build the temporary record-set). and finally, populate the Web-page: with named fields from this record-set.

11 Ian Perry 44238: DWSD: Working with a Remote Database Slide 11 Build the Outline of an AS-page

12 Ian Perry 44238: DWSD: Working with a Remote Database Slide 12 Switch to HTML view & find some insertion points for the VBScript Title Date Category Description  ――― ‘Open’ a ‘remote Database Connection’, and apply a ‘SQL Query’; to select data for the ‘record-set’.  ――― ‘Close’ BOTH the ‘record-set’ AND the ‘remote Database connection’.  ― Build as many ‘Table Rows’ as there are records the ‘record-set’; using a ‘WHILE loop’. }

13 Ian Perry 44238: DWSD: Working with a Remote Database Slide 13 Open the Remote Database & Apply the SQL Query Title Date Category Description <% %> Set MyConn=Server.CreateObject("ADODB.Connection") MyConn.Open "filmlist“ Set Rs=MyConn.Execute("SELECT * From [list]")

14 Ian Perry 44238: DWSD: Working with a Remote Database Slide 14 The full ‘record-set’ (named ‘Rs’) extracted by the SQL Query? However, we only want to display: - Title - Date - Category - Description

15 Ian Perry 44238: DWSD: Working with a Remote Database Slide 15 Use a ‘WHILE loop’, to move through ‘record-set’; creating a new Row for each record, & populating each Cell with data from specific Fields. Set Rs=MyConn.Execute("SELECT * From [list]") WHILE NOT Rs.EOF %> <% Rs.MoveNext WEND %>

16 Ian Perry 44238: DWSD: Working with a Remote Database Slide 16 Always remember to ‘Close’ BOTH the ‘record- set’ AND the ‘remote Database Connection’. <% Rs.MoveNext WEND Rs.Close MyConn.Close %>

17 Ian Perry 44238: DWSD: Working with a Remote Database Slide 17 The resulting Web-page

18 Ian Perry 44238: DWSD: Working with a Remote Database Slide 18 Next Week’s Workshop  Task 1; the structure of the Film List Database.  Task 2; display ALL details, for ALL Films.  Task 3; display ALL details, for ALL Films, SORTED by Category.  Task 4; display PARTIAL details, for ALL Films, SORTED by Date.  Task 5; display ALL details, for Films in the COMEDY Category.  Task 6; display PARTIAL details, for Films with a SPECIFIC Film Star.


Download ppt "44238: Dynamic Web-site Development Working with a Remote Database Ian Perry Room:C48 Extension:7287"

Similar presentations


Ads by Google