Presentation is loading. Please wait.

Presentation is loading. Please wait.

Database Connectivity and Server-Side Scripting Chapter 12.

Similar presentations


Presentation on theme: "Database Connectivity and Server-Side Scripting Chapter 12."— Presentation transcript:

1

2 Database Connectivity and Server-Side Scripting Chapter 12

3 Learn how to… Define the technologies through which Web servers provide client access to server-side databases. Describe the three basic kinds of databases. List the steps in designing a relational database. Define a database connection object and SQL statement. Describe how server-side scripts make decisions based on dynamic database content.

4 Providing Web Access to Server-Side Databases

5 Access to Databases The three-tier Web application model consists of: –User interface –Business object –Back office databases Web sites that provide access to server- side databases are sometimes called HTTP gateways.

6 Access to Databases Data input by users in forms is sent to the business object. The business object can then retrieve, update, delete, or insert information in the database.

7 CGI The common gateway interface (CGI) defines the manner in which a form’s data, cookies, and other kinds of information in a Web request get submitted to the program or script that processes and responds to the request. CGI scripts typically reside in the cgi-bin directory. –CGI scripts can be written in any programming language. Perl is a scripting language for short programs. Bourne shell language is the original UNIX scripting language.

8 SAPI A Server Application Programming Interface (SAPI) is a collection of software components used by the business tier to obtain, process, and respond to a form’s data submitted by users. –SAPI loads once to process multiple requests. –CGI loads separately for each request. –Microsoft’s brand of SAPI is called Internet SAPI (ISAPI). –Netscape’s is called Netscape SAPI (NSAPI).

9 ASP Active Server Page (ASP) is a Microsoft ISAPI technology that enables Web developers to embed on a Web page server-side scripts written in either the JScript or VBScript programming language. –End users see only the result of the scripts, and not the scripts. See the next three slides for example.

10 ASP Source Code

11 Returned HTML Code

12 What the User Sees

13 Java Java is an object-oriented programming language that developers can use to create almost any kind of software. –Java code compiles into an intermediary language that executes on any platform running the JVM. Sun created Java but battles with Microsoft over legalities. –Microsoft can create its own version of Java. –Microsoft will include Sun’s Java Virtual Machine (JVM) in future versions of Windows.

14 Java Servlets and JSP A servlet is a Java applet that runs on the server instead of in the browser; hence the name. Java Server Page (JSP) is an active Web page technology that is Sun’s equivalent to Microsoft’s ASP. –JSP runs in the JVM (Java Virtual Machine). –ASP runs in Microsoft’s ISAPI.

15 PHP The PHP Hypertext Preprocessor (PHP) is another active page technology that enables the Web developer to include code on the page that will run on the server, which executes the code before sending the completed page to the user. –For more information, go to http://us3.php.nethttp://us3.php.net

16 ColdFusion ColdFusion is an active scripting technology that uses its own proprietary scripting language, the ColdFusion Markup Language invented by Macromedia. –ColdFusion pages have the filename extension.cfm, which stands for ColdFusion markup. –Visit www.macromedia.com/software/coldfusion for more information.www.macromedia.com/software/coldfusion

17 ASP.NET ASP.NET allows you to create code behind the Web page, on so-called code- behind pages that can be part of complete applications.

18 Understanding Databases

19 Flat File Database A flat file database keeps all the records in a single file. –It uses comma-delimited data or tab- delimited data to separate entries. –It contains one data table containing rows and columns.

20 Relational Database A relational database contains multiple tables with primary key columns through which the records in one table can relate (i.e. key) to the data in another table. –The primary key is a column in which every entry is unique. –A foreign key is a data field that relates the record to the table in which that same column occurs as a primary key. –The software that powers this type of database is called a relational database management system (RDBMS).

21 Relational Database

22 Object-Oriented Database In an object-oriented database, programmers write code in object-oriented languages to create complex data structures in which one data type can build upon, or inherit, properties from another. –The software is called an object-oriented database management system (ODBMS).

23 Designing Databases Here is an eight-step process to design a relational database: 1.Write a paragraph describing the purpose of the database. 2.Make a list of the tables that the database will comprise. 3.List the fields (data columns) each table will comprise.

24 Designing Databases 4.Indicate the kind of data (data type) that each column will hold. 5.Indicate which data columns are primary keys. 6.Indicate which data columns are foreign keys and state the name of the table and data column in which each foreign key is a primary key.

25 Designing Databases 7.Write a walkthrough to make sure you have not missed anything important. Describe how the typical user will enter your site and navigate its pages. State what will happen in the database as the user submits information. Explain how the data will be used onscreen to create pages whose content vary depending on the content of the database.

26 Designing Databases 8.If you have any data tables with no keys, ask yourself whether the data really stands alone. If not, add the necessary foreign key column to key the data to the primary key column of the data table to which it relates.

27 Normalizing Normalization is the process of separating a large table fulfilling multiple roles into smaller tables that increase efficiency by serving smaller roles that relate through keys to other tables in the database. –Normalized databases contain tables with fewer columns and are more efficient.

28 Indexing An index is a database column or collection of columns that the database engine uses to keep the data presorted in the order in which you plan to query it. –This increases performance.

29 Design Principles 1.Each table should have a column containing a unique row ID number. 2.A table should store data for a single type of entity. 3.A table should avoid columns that are allowed to contain null values. 4.A table should not have repeating values. 5.A field should have the same meaning in each row of a table. 6.Multiple instances of an entity should not be represented as multiple columns.

30 Accessing Server-Side Databases

31 Three-Tier Model

32 Major Databases The major brands of databases include Microsoft SQL Server, Oracle 9i, Borland Interbase, IBM DB2, and iPlanet Application Server. Standards define alternate means for connecting with databases. –ODBC –JDBC

33 ODBC Open database connectivity (ODBC) is a Microsoft standard database access method. –The goal is to make it possible for any application to access any database, regardless of its vendor. –ODBC uses database drivers that translate queries and commands issued by the application into a format that the database can process. –An ODBC driver exists for almost every brand of relational database.

34 JDBC Java database connectivity (JDBC) enables Java programs to communicate with SQL-based database systems.

35 OLE DB Data Sources Object linking and embedding database (OLE DB) enables Windows applications to open a wide variety of connections to data stored in all sources and not only in ODBC data sources.

36 ADO ActiveX Data Objects (ADO) is an API that enables business objects to make connections and issue commands against different kinds of data sources.

37 Creating an ADO Object The connection object is the ADO component that connects you to the database. –Once you have the connection open, you can execute queries that insert, update, retrieve, or delete records from the database. –The next slide shows the code to open a connection in two different ASP languages.

38 Creating an ADO Object

39 Sample Connection Strings

40 SQL The Structured Query Language (SQL) is an international standard that defines the syntax for issuing commands that can query, update, insert, or delete records in a database. The SELECT command is used to retrieve records from a data table.

41 SELECT Command

42 SELECT Order

43 SELECT Search

44 Creating Data-Driven Web Pages

45 Data-Drive Web Page A data-driven Web page is an HTML document in which part or all of the content derives from or depends on records or relationships in one or more databases. –Queries return data in a set of records called a recordset. –The next few slides show some ASP code that reads data from a recordset and makes decisions based on the status of this data.

46 Preface The following script reads the names of registered users from a Users table and prints the names onscreen. Each comment line begins with the symbol //

47 Jscript Version

48 VBScript Version

49 Using Logic The true power of data-driven Web pages comes from the script’s ability to make decisions based on the current contents of the database. –Suppose you want to check a user database to decide whether to allow a user to log on to gain access to a Web page. What steps would be needed?

50 Logical Steps for Login 1.Retrieve the user name and password from the incoming form data. 2.Open a connection to the username database. 3.Issue an SQL command to query the database. 4.Use an IF-THEN statement to make the following decision based on the query result: –If the recordset is empty, this user is not valid, so you deny access. –If the recordset contains the requested record, the user is allowed in.

51 JScript Version

52 VBScript Version

53


Download ppt "Database Connectivity and Server-Side Scripting Chapter 12."

Similar presentations


Ads by Google