Sie sind auf Seite 1von 12

Chapter 7 Installing and Testing a Programming Environment

At a Glance

Instructors notes
Chapter Objectives Instructor Notes Discussion Topics Quick Quizzes Key Terms

CHAPTER OBJECTIVES
Understand the need for programming languages Understand database management systems (DBMSs) Install and test DBMSs Understand the Web-based programming environment Program with databases

INSTRUCTOR NOTES
The need for programming languages As you have learned, Web pages with just HTML statements are called static pages. Pages that contain programming statements allow changes and they are called dynamic pages. Programming languages can also be used to update databases and communicate with other systems. Database management systems (DBMSs) The purpose of a DBMS is to store data in an organized manner for further processing. Virtually all DBMSs use Structured Query Language (SQL) as the language used to define and manipulate the data. Most databases are relational and organize data into tables. Database Tables A primary key uniquely defines a row of data. For example, the SSN in the Employee table and Department number in the Department table would be primary keys. That is, there are no duplicate SSNs or department numbers. Each SSN is associated with a unique employee. A foreign key is a column in a table that is related to a primary key. For example, an employee belongs in a department so there is a department number in the Employee table. This department number is associated with the department number in the department table. Three categories of SQL Data Manipulation Language (DML) - Used for programming for inserting, updating, deleting and retrieving data. Data Definition Language (DDL) - Used to create tables and other related structures in a database Data Control Language (DCL) - Allows you to control access to tables Installing and testing SQL Server As with other applications, a wizard guides you through the installation By default, it uses the user name you logged on as (typically administrator) to gain access to the system This should be changed to "Use the Local System account" for single server systems If SQL Servers need to communicate with other servers, create a special domain account

QUICK QUIZ
1. True/False. Web pages that contain only HTML statements are called dynamic pages. Answer: False 2. True/False. In an employee table, all the information for a single employee would correspond to a row. Answer: True 3. What is the language that DBMSs use to manipulate data? Answer: SQL 4. What is the category of SQL statements most common in programming? Answer: DML

Installing and testing SQL Server Although the wizard guides you through the installation, there are a few critical issues to consider. For the authentication mode, the Windows Authentication Mode controls access to the database based on Windows users. The Mixed Mode allows for SQL Server Authentication. The Mixed Mode is more appropriate for Web-based systems and must be chosen in order to do the lab assignments. The sa (systems administrator) account is a SQL Server user that has complete control over the databases. For the examples, it is assumed that the sa account has a blank password, which in the real world would be very dangerous. Creating tables in SQL server is very easy. The GUI interface is similar to Access in creating a table. Filling tables with data is also easy. Although SQL statements are often used to manipulate data, you can use something similar to a spreadsheet to enter data. Installing and testing MySQL for Red Hat Linux As with other applications, you run an RPM file. Once it is installed, you start MySQL with: /etc/rc.d/init.d/mysqld start Administering MySQL is done through a command-line interface which is accessed by typing: mysql The first thing you should do after you install MySQL is create password for mysql root account with the following typed from the MySQL command-line interface: SET PASSWORD FOR root=PASSWORD('password'); When you want to create a database, you have to log in to mysql. Assuming that you have already created a password for root, you log in from shell prompt with: mysql uroot ppassword To create a database called hr: create database hr; In order to do any operations on the database such as create tables, you have to "use" it: use hr; In order to create tables and insert data, you have to execute the correct SQL statements. To save you time, there is a script that creates the employee table and adds three employees: create table employee ( ssn char(9) primary key,

firstname varchar(20), lastname varchar(30), deptno char(2), salary numeric(6)); insert into employee values('553879098','Lynn','Gweeny',10,55000); insert into employee values('623827368','Elark','Kaboom',10,60000); insert into employee values('756838998','John','Doh',20,45000); Common terms in a Web-based programming environment Cookie - Text that a Web site stores on your disk Common Gateway Interface (CGI) - A protocol that allows the operating system to interact with the Web server. Practical extraction and reporting language (Perl) - First popular language for Web servers. Java Server Pages (JSP) - Language similar to Java. Active Server Pages (ASP) - script-based environment available on all IIS Web servers. ASP.NET - Compiled programs operate under .NET Framework. .NET Framework is an integral part of Windows Server 2003 and can be installed on Windows 2000. PHP Hypertext Protocol (PHP) - Popular language available on most platforms. The structure of JSP, ASP, and PHP are similar.

QUICK QUIZ
1. True/False. DSN stands for Database Sequence Number. Answer: False 2. In MySQL, the command to create a database called inventory would be what? Answer: create database inventory; 3. What does CGI stand for? Answer: Common Gateway Interface

Using forms The following HTML produces a form

When the submit button is pressed, the data in the form is sent to the file designated as filename. Using ASP to process form The following file displays the information from the form

Notice how the items such as "first" match the text names on the form. ASP uses <% and %> for opening and closing tags. <%=request()%> is one way to retrieve data from the form. ASP.NET ASP.NET is one of the many languages available under the .NET Framework that can be used for the Web. The programming model of ASP.NET is superior to that of ASP. ASP.NET has modules for data validation that differentiates between browsers. Producing sophisticated reports much easier. ASP.NET program that combines form and output

The following shell script in Linux uses CGI:

First line states that the shell is being used which is not common because of lack of security. The following Perl script to display contents of form:

Notice how $cgi->param("first") is similar to ASPs request("first") Programming with databases Microsoft uses two methods to bridge the gap between programming languages and databases: Open Database Connectivity (ODBC) which is the original standard. Object Linking and Embedding Database (OLEDB) The current standard which is faster and more flexible Linux often uses Java Database Connectivity (JDBC) You can also have a direct connection between the language (such as PHP) and the database (such as MySQL). There are a number of steps to producing a report: 1. Connect to the database 2. Execute a SQL select statement to retrieve data from a table 3. Put the data in a recordset. It is also known as a resultset, depending on the environment 4. Loop through the recordset and display the contents A report in ASP:

Using Data Source Names (DSNs) DSNs are connections to databases that an administrator creates on the server. They encapsulate the information concerning the connection information. The Data Sources (ODBC) wizard is in the Control Panel. Once the DSN is created, you can create a connection with Conn.open "DSN=humanresources;uid=sa" Programming with ASP.NET Although there is a connection and you send it a SQL select statement, the DataGrid component creates the report:

Programming with PHP Note the similarity between ASP and PHP, and how different they are from ASP.NET:

QUICK QUIZ
1. True/False. DSNs represent connections to databases. Answer: True 2. True/False. <% is the opening tag in PHP. Answer: False

3. What acts as an intermediary between the DBMSs and the programming languages? Answer: ODBC.

Discussion Topics
1. Explain the difference between a primary key and a foreign key. Use examples. 2. Compare and contrast ASP and PHP with regard to syntax and structure. 3. Compare and contrast ASP and ASP.NET with regard to syntax and structure.

Key Terms
Active Server Pages.NET (ASP.NET) The latest generation of programming environment that allows for more productive programming, it is used to create dynamic pages. Based on Active Server Pages (ASP), this Web-based programming language was created by Microsoft for Windows Web servers. Common Gateway Interface (CGI) A protocol that allows the operating system to interact with the Web server. cookie Text that a Web site stores on your disk that can be retrieved by the Web server whenever you visit the site. Data Control Language (DCL) The part of SQL that controls access to the data, often through user names and passwords. Access can be controlled by specific DML statements. Data Definition Language (DDL) The part of SQL that creates the tables and other objects in a database. Data Manipulation Language (DML) The part of SQL that does the inserting, updating, deleting, and selecting of data. The DML is the most common part of SQL used in programming. database management system (DBMS) A system that stores data on a computer in an organized format. It typically uses SQL as the language to define and manipulate the data, and stores data in an organized manner for processing. Extensible Markup Language (XML) A technology that allows developers to create text files that contain tags that define information. Data can then be sent in text form that can be interpreted by otherwise incompatible systems. foreign key A column in one table that is related to a primary key in another table. iteration A programming structure where the same instructions are processed multiple times. Java Database Connectivity (JDBC) A technology that enables Java programs to execute SQL statements. Linux uses JDBC works in much the same way that Windows uses ODBC. See also ODBC. JavaServer Pages (JSP) A Web-based scripting language that uses a subset of the Java language. The code is compiled into a Java servlet before it runs for the first time after changes are made to the file. Object Linking and Embedding Database (OLE DB) A database that stores objects that can be embedded in a variety of programs. Open Database Connectivity (ODBC) A technology that acts as an intermediary between the DBMS and the programming language. PHP Hypertext Protocol (PHP) A Web-based scripting language commonly used with Apache Web servers. Also called PHP Hypertext Preprocessor. Practical Extraction and Reporting Language (Perl) A language that predates the Web and is used to process text. primary key In a table, one or more columns whose values uniquely define the contents of the row. row Data stored in a record in a database table. static Web page A page that contains only HTML statements and is sent to the browser without any processing. The typical extension for such pages is .htm or .html.

Structured Query Language (SQL) The language used to interact with a relational DBMS.

Das könnte Ihnen auch gefallen