Chapter 22 22.1 Fill in the blanks in each of the following statements: a) The international standard database language is SQL. b) A table in a database consists of rows and columns. c) The primary key uniquely identifies each row in a table. d) SQL keyword WHERE is followed by the selection criteria that specify the rows to select in a query. e) SQL keywords ORDER BY specify the order in which rows are sorted in a query. f) Merging rows from multiple database tables is called joining the tables. g) A(n) database is an organized collection of data. h) A(n) foreign key is a set of columns whose values match the primary key values of another table. 22.2 Define the following terms: a) Qualified name. The fully qualified name of an object consists of four identifiers, the server name, database name, schema name, and object name. Typically, a qualified name simply means that the table name and column or row name is specified when using a clause for query. b) Rule of Referential Integrity. The rule of referential integrity requires that every foreign-key value must appear as another table's primary-key value. c) Rule of Entity Integrity. The rule of entity integrity requires that the table's primary-key must uniquely identify each row in the table. d) System.Data. System.Data is the root namespace fo the ADO.NET API. e) selection criteria. When running a query, it is necessary to select data that meets a certain selection criteria. This can be done with a "WHERE" clause that contains certain operators for determining value ranges. 22.3 State the purpose of the following SQL keywords: a) ASC This keyword will sort data returned from a query in an ascending order. b) FROM This keyword specifies the tables involved in the query. c) DESC DESC will sort data returned from a query in descending order. d) INSERT This command will insert a row or rows into a specified table. e) LIKE This command will return results that match a given pattern. f) UPDATE This command will update rows in a given table. g) SET This keyword will set the values of given columns in a row within an UPDATE command. h) VALUES The VALUES keyword is used in conjunction with "INSERT INTO" for creating a new row of values in a table. The values are separated by commas and will be inserted into the column names that were specified by the INSERT INTO command. i) ON The ON clause specifies a condition that determines which rows are combined. 22.4 Write SQL queries for the books database (discussion in Section 22.3) that perform each of the following tasks: a) Select all authors from the Authors table with the columns in the order lastName, firstName and authorID. SELECT lastName, firstName, authorID FROM authors b) Select a specific author and list all books for that author. Include the title, year and ISBN number. Order the information alphabetically by title. SELECT firstName, lastName, title, year, ISBN FROM authors, authorISBN, titles WHERE authorID = 1 ORDER BY title ASC c) Add a new author to the Author table. INSERT INTO authors ( authorID, lastName, firstName ) VALUES ( 5, 'Talbott', 'Josh' ) d) Add a new title for an author (remember that the book must have an entry in the AuthorISBN table). INSERT INTO authorISBN, titles( authorISBN.authorID, authorISBN.ISBN, titles.ISBN, titles.title, titles.editionNumber, titles.copyright ) VALUES ( 5, XX-XXXXX, XX-XXXXX, 'How to Be Awesome', 1, 2011 ) 22.5 Fill in the blanks in each of the following statments: a) The the rule of entity integrity states that every column in a primary key must have a value, and the value of the primary key must be unique. b) The rule of referential integrity states that every foreign-keyvalue must appear as another table's primary-key value. c) A(n) percent character in a pattern indicates that a string matching the pattern can have zero or more characters at the percent character's location in the pattern. d) Java DB is the Sun branded version of MySQL. e) A(n) underscore in a LIKE pattern string indicates a single character at that position in the pattern. f) There is a(n) one to many relationship between a primary key and its corresponding foreign key. g) SQL uses single quote as the delimiter for strings. h) Microsoft's ADO object model provides an API for accessing database systems programmatically. 22.6 Correct each of the following SQL statements that refer to the books database. a) SELECT firstName FROM author WHERE authorID = 3 SELECT firstName FROM authors WHERE authorID = 3 b) SELECT isbn, title FROM Titles ORDER WITH title DESC SELECT isbn, title FROM titles ORDER by title DESC c) INSERT INTO Authors ( authorID, firstName, lastName ) VALUES ( "2", "Jane", "Doe" ) INSERT INTO authors ( authorID, firstName, lastName ) VALUES ( 2, 'Jane', 'Doe' ) Chapter 23 23.1 State whether each of the following is true or false. If false, explain why. a) PHP script is never in the same file as XHTML script. False. PHP is directly embedded directly into XHTML. b) PHP variable names are case sensitive. True. c) The settype function only temporarily changes the type of a variable. False. Function settype permanently changes the type of a variable. d) Conversion between data types happens automatically when a variable is used in a context that requires a different data type. True. e) The foreach statement is designed specifically for iterating over arrays. True. f) Relational operators can only be used for numeric comparison. False. Relational operators can also be used for alphabetic comparison. g) The quantifier +, when used in a regular expression, matches any number of the preceding pattern. False. The quantifier + matches one or more of the preceding pattern. h) Function die never takes arguments. False. Function die has an optional argument -- a string to be printed as the script exits. i) Cookies are stored on the server computer. False. Cookies are stored on the client's computer. j) The * arithmetic operator has higher precedence than the + operator. True. 23.2 Fill in the blanks in each of the following statements: a) PHP scripts typically have the file extension php. b) The two numeric types that PHP variables can store are int or integer, float or double. c) In PHP, uninitialized variables have the value undef. d) Arrays are divided into elements, each of which acts like an individual variable. e) Function count return the total number of elements in an array. f) To use POSIX regular expressions, use the ereg functions. g) A(n) character class in a regular expression matches a predefined set of characters. h) Data submitted through the HTTP post method is stored in array $_POST. i) Function die terminates script execution. j) Cookies can be used to maintain state information on a client's computer. 23.3 Identify and correct the error in each of the following PHP code examples: a) <?php print( "Hello world" ); > This problem is missing "?>" to end the PHP script. ">" is not enough. b) <?php $name = "Paul"; print( "$Name" ); ?><!-- end PHP script --> The variable "name" can not be recalled by and uppercase "Name" for the print statement. 23.4 Write a PHP regular expression pattern that matches a string that satisfies the following description: The string must begin with the (uppercase) letter A. Any three alphanumeric characters must follow. After these, the letter B (uppercase of lowercase) must be repeated one or more times, and the string must end with two digits. "[[:< : ]](A[[:alpha:]]{3}+[bB]+[a-zA-Z0-9]+[[:digit:]]{2})[[:>:]]" 23.5 Describe how input from an XHTML form is retrieved in a PHP program. A user submits information to the server via a $_GET or $_POST command. The field key and values are carried into the superglobal arrays for GET or POST. To use the data a function "expand" in the php script is called to create the variable/value pairs to use within the script. 23.6 Describe how cookies can be used to store information on a computer and how the information can be retrieved by a PHP script. Assume that cookies are not disabled on the client. Cookies are a text document with values that can be given an expiration date for when they are no longer needed. PHP can write them with the setcookie function and read them with the $_COOKIE superglobal variable.