1 / 53

Database Connectivity and Server-Side Scripting Chapter 12

Database Connectivity and Server-Side Scripting Chapter 12. 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.

demitrius
Télécharger la présentation

Database Connectivity and Server-Side Scripting Chapter 12

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Database Connectivity and Server-Side Scripting Chapter 12

  2. 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.

  3. Providing Web Access to Server-Side Databases

  4. 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.

  5. 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.

  6. 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-bindirectory. • CGI scripts can be written in any programming language. • Perl is a scripting language for short programs. • Bourne shell languageis the original UNIX scripting language.

  7. 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).

  8. 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.

  9. ASP Source Code

  10. Returned HTML Code

  11. What the User Sees

  12. Java • Javais 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.

  13. Java Servlets and JSP • A servletis 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.

  14. 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.net

  15. ColdFusion • ColdFusionis 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.

  16. 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.

  17. Understanding Databases

  18. Flat File Database • A flat file databasekeeps all the records in a single file. • It uses comma-delimited dataor tab-delimited datato separate entries. • It contains one data table containing rows and columns.

  19. Relational Database • A relational databasecontains 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 keyis a column in which every entry is unique. • A foreign keyis 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).

  20. Relational Database

  21. 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).

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

  23. Designing Databases • Indicate the kind of data (data type) that each column will hold. • Indicate which data columns are primary keys. • 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.

  24. Designing Databases • 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.

  25. Designing Databases • 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.

  26. Normalizing • Normalizationis 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.

  27. Indexing • An indexis 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.

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

  29. Accessing Server-Side Databases

  30. Three-Tier Model

  31. 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

  32. 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.

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

  34. 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.

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

  36. 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.

  37. Creating an ADO Object

  38. Sample Connection Strings

  39. 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.

  40. SELECT Command

  41. SELECT Order

  42. SELECT Search

  43. Creating Data-Driven Web Pages

  44. Data-Drive Web Page • A data-driven Web pageis 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.

  45. 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 //

  46. Jscript Version

  47. VBScript Version

  48. 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?

  49. Logical Steps for Login • Retrieve the user name and password from the incoming form data. • Open a connection to the username database. • Issue an SQL command to query the database. • 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.

More Related