Web Development II
What is stored in $message by the code that follows? $message = "The file is in \"C:\\My Documents\"";
The file is in "C:\My Documents"
To catch all exceptions and errors using a single catch block, you can use the ________________ interface.
Throwable
Which SQL statement will select a database?
USE
In a SQL statement, the ________________ clause specifies the rows to retrieve.
WHERE
Which clause in a SQL statement specifies the records to return based on criteria?
WHERE
Which date string matches the pattern that follows? /^[01]?\d\/[0-3]\d\/\d{4}$/
"02/34/1968"
Which character is used to signify the end of the string in a PHP regular expression?
$
To get the value of a cookie, you can use the autoglobal ______________ variable.
$_COOKIE
A session ID lets PHP associate a user with the data that's stored in the related
$_SESSION variable
To create a DateTime object that represents a due date that's 90 days after the current date, you use the following code:
$days = new DateInterval('P90D'); $due_date = new DateTime(); $due_date = $due_date->add($days);
Suppose that $name contains a last name followed by a comma and a space, followed by a first name. Then, you can store the first and last names in variables with code like this:
$i = strpos($name, ', '); $last_name = substr($name, 0, $i); $first_name = substr($name, $i+2);
Given the code that follows, which of these statements assigns "John Smith is 29" to $message?$employees = [];$employees['name'] = "John Smith";$employees['age'] = 29;
$message = $employees["name"] . " is " . $employees["age"];
Suppose that $name contains a last name followed by a comma and a space, followed by a first name. Then, you can store the first and last names in variables with code like this:
$name = explode(', ', $name); $last_name = $name[0]; $first_name = $name[1];
To round and format the value of a variable named $number to 3 decimal places and store it in a variable named $number_formatted, you code
$number_formatted = number_format($number, 3);
(Refer to code example 14-1) Given a variable named $vehicle that contains an instance of the Vehicle enum and this class that includes a private property for the Vehicle enum:class Owner {private Vehicle $vehicle;public function getVehicle() { return $this->vehicle;}public function setVehicle(Vehicle $vehicle) { $this->vehicle = $vehicle;}}what code would you use to set the value of the enum in the class?
$owner = new Owner(); $owner->setVehicle($vehicle);
Which parameter of the session_set_cookie_params() function can be set so the cookie is only available on an HTTPS connection?
$secure
Which of the following is the correct way to execute a prepared PHP statement named $statement if the PDO object is $db?
$statement->execute();
Because most systems today store timestamps as 32-bit signed integers, the upper limit of a timestamp on these systems is January 19 in the year________________.
2038
Which of the following is a relational operator in PHP?
<,<=,> all of these
A PHP tag that's embedded within HTML starts with
<?php
The nl2br() function can be used to convert new line characters that a user has entered into a text area into ________________.
<br> tags
Which of the following operators does NOT perform type coercion?
===
Which character is used to separate the original URL from the parameters that are appended to it?
?
To modify the structure of an existing table, you use the ________________ statement.
ALTER TABLE
MySQL provides a/an ________________ that specifies how any application can work with MySQL.
API
Which of the following methods of using PHP to connect to a MySQL database allows you to write code that is portable across different database servers?
PDO MySQL driver extension
Typically, you would use the ________________ if a form contains password fields or other sensitive data that you don't want to display in the URL.
POST method
What does the acronymn PRG stand for?
Post-Redirect-Get
A subquery is a/an ________________ statement that's coded within another SQL statement.
SELECT
Which clause in a SQL statement specifies the columns to return?
SELECT
When you create a PDO object, you have to pass all but one of these arguments to it: Which one is it?
Server name
To pass one or more values to a function, the function must be defined with
a parameter for each value
What is the value of $result after the code that follows is executed?$string1 = 'Murach';$string2 = 'harris';$result = strcasecmp($string1, $string2);
a positive number
When you use the header() function to redirect a request,
a response is returned to the browser that tells it to request another page
A subquery can return
a result set, a column of one or more rows, a single value all of these
To be in the first normal form, each cell in a table must contain
a single, scalar value
Google Chrome is
a web browser
What software does a client use to access the web server where a web application resides?
a web browser
To make it easier to enter names into your code, NetBeans provides a feature known as
auto-completion
When you use a prepared SQL statement with PDO, you need to ________________ values to the parameters before you can run the statement.
bind
To execute a prepared SQL statement, you can use the ________________ and execute() methods of the PDOStatement object to set parameter values and execute the statement.
bindValue()
To load data from a text file to a table in a MySQL database, you can use
both a and b a. phpMyAdmin b. the MySQL LOAD command
Which type of statement ends or jumps out of a loop?
break
When debugging an application, you can set a(n) ________________ to view the value of a variable at a particular point.
breakpoint
Which PHP function returns the number of elements in an array?
count()
When coding relative URLs, you can begin the URL with a single dot (.) to indicate that the URL should start with the ________________ directory.
current
Unlike the tables that came with versions of MySQL before version 5.5, the InnoDB tables that are the default for recent versions of MySQL provide for
declarative referential integrity
A column in a table that can be computed from other columns contains ________________ data.
derived
Which of the following is a method of a DateTime object that can be used to determine an amount of time between two dates or times?
diff()
When you use the htmlspecialchars() and nl2br() functions to process a user's entry and then pass that entry to a web page, the browser will
display any HTML tags entered by the user instead of processing them
A hidden field
doesn't appear on the form but its data is sent to the server
What type of web pages are generated by PHP scripts that are running on the web server?
dynamic
A simple way to trace the execution of an application is to insert ________________ statements at appropriate points within the code.
echo
What does $salutation contain after the following code executes?$company_name = '';$salutation = $company_name ?? 'To whom it may concern';
empty string ('')
To create a default value for a parameter in the parameter list of a function, you code a/an ________________ after the parameter name followed by the default value.
equal operator
Which of the following can be used in a conditional expression?
equality operators, relational operators, logical operator: all of these
What can you use to put special characters into a string literal that would otherwise be interpreted incorrectly by PHP?
escape sequences
A/An ________________ is an object that contains information about an error.
exception
Which of the following is an object that contains information about an error that occurred?
exception
Which function can be used to redirect a request to another URL?
header()
What modifier can be added to the end of a regular expression in PHP to make it case insensitive?
i
An inner join combines data from two or more tables
if the primary key and foreign key are equal
A cookie is a name/value pair that's stored
in the user's browser
A(n) ________________ provides a way for a database management system to locate information more quickly.
index
If two tables have a many-to-many relationship, you need to define a/an ________________ table that relates their rows.
linking
Which attribute of a form element determines how the data is passed to a file?
method
Which of the following consists of the PHP files that represent the data of the applications?
model
The ________________ operator divides one operand by another operand and returns the remainder.
modulus
Denormalization typically results in all but one of the following. Which one is it?
more complicated SQL coding
Which optional attribute of a select element allows the user to select more than one option in a list box?
multiple
Which of these would NOT be considered a common syntax error in PHP?
multiplying by the wrong variable
The prepare() method of a PDO object
must be run before values are assigned to the parameters in a prepared statement
Which of the following is the oldest method of using PHP to connect to a MySQL database?
mysql extension
In the object-oriented interface for mysqli, you can use the query() method to run a SELECT statement. In the procedural interface, you use this function:
mysqli_query()
To create a DateTime object for the current date, you use the ________________ keyword and pass no arguments to the constructor.
new
To create an object from a class, you code the ________________ keyword followed by the class name and an argument list.
new
If a row in one table is related to just one row in another table, the tables are said to have a
one-to-one relationship
When a new class extends a superclass, it inherits the properties and methods of the superclass. Then, it can
override the inherited methods
The first part of a URL is called the
protocol
A ________________ is a special type of array that implements a first-in, first-out collection of values.
queue
To apply the second normal form, you move columns that don't depend on the entire primary key to another table and establish a relationship between the two tables. This
reduces redundancy and makes maintenance easier
A list of functions or methods in the reverse order in which they were called is a/an
stack trace
Which type of error is considered the easiest to find?
syntax
Once a session is started, which superglobal variable can be used to get and set the user's data for a session?
$_SESSION
What extension of a filename is typically associated with a static Web page?
.htm
How many times will the while loop that follows be executed?$months = 5;$i = 1;while ($i > $months) {$futureValue = $futureValue * (1 + $monthlyInterestRate);$i = $i+1;}
0
If a regular expression is found in the string that's specified by the preg_match() function, the function returns ________________.
1
If $today contains a DateTime object for December 25, 2021, what output would be produced by the code below? echo $today->format('n/j/Y');
12/25/2021
If $today contains a DateTime object for December 25, 2021, what output would be produced by the code below? echo $today->format('n/d/Y h:i A');
12/25/2021 12:00 AM
If $today contains a DateTime object for December 25, 2021, what output would be produced by the code below? echo $today->format('n/j/y');
12/25/21
How many times will the for loop that follows be executed?$years = 25;for ($i = 1; $i < $years; $i++) {$future_value = ($future_value + ($future_value * $interest_rate));}
24
How many error modes are available when using PDO to execute SQL statements?
3
What will the value of the $numbers array be after the following code is executed?$numbers1 = [3, 4, 5];$numbers2 = [8, 9];$numbers = [...$numbers1, ...$numbers2];
3, 4, 5, 8, 9
Which character can be used to suppress errors in PHP?
@
If a match is found when the preg_split() function is executed, it returns
An array of the substrings that are created by removing the matches
What type of SQL statement is used to assign user privileges in MySQL?
GRANT
In which of the following clauses can you NOT introduce a subquery?
GROUP BY
What does $salutation contain after the following code executes?$salutation = 'Greetings';$salutation ??= $company_name;
Greetings
The ________________ statement can be used in SQL to add a new row to a table.
INSERT
To retrieve rows in which an expression matches a string pattern called a mask, you can use the ________________ operator followed by the mask.
LIKE
What does the acronym MVC stand for?
Model-View-Controller
The ________________ operator has the highest order of precedence of the logical operators.
NOT
What does routine 1 store in the variable named $category_name?
The category name for the row in categories table that corresponds to the value in $category_id
Which character is used to signify the beginning or the end of a word in a PHP regular expression?
\B
Which character is used to signify the beginning of the string in a PHP regular expression?
^
A request and response for a file are made by
a client and a server
When you use session tracking, each HTTP request includes
a cookie that stores the session ID
To create a DateTime object based on the date and time you specifiy, you use a/an ________________ template.
absolute
Which of the following is a method of a DateTime object that can be used to add a period of time to the date?
add()
Which of the following is a property of the mysqli class that can be used for checking the result of a query?
affected_rows, insert_id, errord all of these
Which of the following is NOT true about a MySQL table unless you specify otherwise?
all columns have a default value
Which of the following is a way to assign a string to a variable in PHP?
all of these (single quotes, double quotes, heredoc)
Which of the following is a PHP function for sorting arrays?
all of these (sort(), rsort(), krsort() )
Code example 3-1SELECT vendorName, invoiceNumber, invoiceDate, invoiceTotalFROM vendors INNER JOIN invoicesON vendors.vendorID = invoices.vendorIDWHERE invoiceTotal >= 500ORDER BY vendorName DESC (Refer to code example 3-1.) If vendorName contains string data and invoiceTotal contains decimal values, how will the result set be ordered?
alphabetically starting with Z
To normalize a data structure, you
apply the normal forms in sequence
When you call a function, you can pass ________________ as values that correspond to the parameters of the function.
arguments
Which PHP function returns an array with the elements of two or more arrays in one array?
array_merge()
An array that uses strings as indexes in PHP is known as a/an ________________ array.
associative
When a primary key consists of two columns, you need to define the key
at the table level
In HTML, parameters are called
attributes
Runtime errors that occur due to unexpected error conditions are called ________________.
exceptions
Which method of a PHP Data Object can be used to execute dynamic INSERT, UPDATE, and DELETE statements?
exec()
To return an array for the first row of a result set that's returned by a SELECT statement, you use the ________________ method of the PDOStatement object for the result set.
fetch()
Which of the following is a method of the PDOStatement class that returns an array for the next row in a result set?
fetch()
Which of the following is a method of the PDOStatement class?
fetch(), fetchAll(), bindValue() all of these
After you run a prepared SQL statement with PDO, you can use the ________________ method of the PDOStatement object to get an array that corresponds to the rows in the result set.
fetchAll()
To get an array for all rows in a result set, you can call the ________________ method of the PDOStatement object for the result set.
fetchAll()
A function library is just a/an ________________ that contains one or more functions.
file
Which of the following functions can you use to validate a URL?
filter_var()
To create a class that can't be inherited by a subclass, you include the ____________ keyword on the class declaration.
final
The goal of testing is to
find all errors in the application
If two tables have a one-to-many relationship, you may need to add a _____________ column to the table on the "many" side.
foreign key
To enforce referential integrity, you can define a/an ________________ constraint.
foreign key
When you ________________ a request, all processing takes place on the server.
forward
All of the arguments that are passed to a function are available in an array that can be accessed by using the
func_get_args() function
A method is a/an ________________ that's coded within a class.
function
When you use the procedural interface of mysqli, you use ________________ to perform the database operations.
functions
To get the message that's related to an exception, you use the
getMessage() method of the exception object
The lastInsertID() method of the PDO class
gets the ID for the last record with an auto-increment ID that has been inserted into a database
Which of the following functions can you use to send special characters to the browser in a way that they will be displayed correctly?
htmlentities() function
Which PHP function converts some special characters into character entities?
htmlspecialchars()
Which URL can be used to start phpMyAdmin on a local system?
http://localhost/phpmyadmin
To refer to the elements in an array, you use a string or numeric ________________.
index
Which of the following can be displayed if you omit the filename of a URL?
index.htm index.html index.php All of these
To speed performance when searching and joining tables, you can use ____________.
indexes
Variable substitution is carried out by what process that converts a variable's value to a string?
interpolation
The $_SESSION variable for a session
is an associative array
A PHP variable name
is case-sensitive
One reason for using the header() function to redirect a request
is to have a PHP file run itself again
Which PHP function can be used to determine if a checkbox is checked?
isset()
A variable declared inside a PHP function would be considered a ____________ variable.
local
If you declare a variable within a function, the variable has ________________ scope.
local
What keyword must you code to create a PDO object?
new
To create an object from a class named Cart that requires two arguments, you code
new Cart($arg1, $arg2)
In an if statement, the statements in the else clause are executed if
none of the conditions in the if or elseif clauses are true
When this query is executed, the numberOfInvoices column for each row will show the number
of invoices for each vendor that have a larger balance due than the average balance due for all invoices
The most common type of relationship between tables in a relational database is
one-to-many
When creating functions, you can include ______________ that are located inside parentheses after the function name.
parameters
A regular expression defines a/an ________________ that can be searched for in a string.
pattern
A cookie that does not expire when the user closes his or her browser is a(n) ________________ cookie.
persistent
Which function searches for a regular expression in a string and returns 1 if the pattern is found?
preg_match()
Which of the following functions is used to replace a substring that is matched by a regular expression with a new substring?
preg_replace()
Every row in a table should be uniquely identified by a ________________ key.
primary
What does a relational database use to uniquely identify each row in a table?
primary keys
To code a constructor for a class named Cart that requires two arguments, you can start with this code:
public function __construct($arg1, $arg2) {
To prevent other classes from directly accessing the properties of a class, you can code them as private. Then, to make them available to other classes, you can code
public methods to set and get their values
A "natural" comparison of two values
puts both "09" and "9" before "10"
Which method of a PHP Data Object can be used to execute a dynamic SELECT statement?
query()
Which of the following is a term that refers to modifying the organization or structure of an application?
refactoring
Which of the following are coded patterns that you can use to search for matching patterns in text strings?
regular expressions
To create a DateTime object based on an offset you specify to the current date and time, you use a/an ________________ template.
relative
To view the source code for a web page in a web browser, you can display the View Page Source command by
right-clicking on the page
If you want to round a number within an arithmetic expression, which function should you use?
round()
Which type of error does not violate the rules for how PHP statements must be written but will cause the PHP interpreter to display errors?
runtime
A timestamp stores the number of ________________ since midnight on January 1, 1970 GMT.
seconds
An if statement can be used to implement a ________________ structure.
selection
Which PHP function can be used to end a session?
session_destroy()
Which PHP function is used to create a cookie?
setcookie()
Gaps can be introduced into an array in all of the ways that follow, exept one. Which one is it?
store an empty value in an array
A/an ________________ error violates the rules for how PHP statements must be written.
syntax error
To model a database on a real-world system, you typically represent each real-world entity as a/an ________________.
table
As you ________________ an application, you try to make it fail.
test
When you test an application with NetBeans and a breakpoint is reached, you can click
the Step Into button to execute the current statement and move to the next statement
It is usually not a good practice to create an index for a column when
the column is frequently updated
Which of the following does a function start with in PHP?
the function keyword
When you create an exception, you can code the new keyword followed by the name of the ________________ that defines the exception followed by a set of parentheses that contains the message for the exception.
the name of the class that defines the exception the message for the exception the error code for the exception (all of these)
When INSERT, UPDATE, or DELETE statements are used in conjunction with a PHP Data Object, what is returned?
the number of rows that were affected
When you identify the data elements in a new database, you typically subdivide data elements into
the smallest practical components
A database is typically considered normalized if it is in ________________ normal form.
third
For a table to be in ___________ normal form, every non-key column must depend only on the primary key.
third
If you want to create an exception within a data validation function and throw it to the statement that called the function, you code
throw new Exception("Validation error");
To refer to an element in a rectangular array, you need to use ________________ indexes.
two
To declare that a parameter can have more than one type, you can use a/an
union type
When you use the exception error mode with PDO objects, you can
use try/catch statements to handle the exceptions that occur
By default, all arguments passed to PHP functions are passed by ________________.
value
When a breakpoint is reached while you're testing an application with NetBeans, you can view the values of the available ________________.
variables
The column definition for a MySQL table can be used to determine all but one of the following. Which one is it?
what range of values the column can contain
Which of the following can you NOT specify when creating an index?
whether the index is for a foreign key
When you create a DateInterval object, you pass it one argument that specifies one or more of the following:
years, months, weeks, days, hours, minutes, seconds
What output would be produced by the code below?$names = ['Ron Burgundy', 'Brick Tamland', 'Champ Kind', 'Veronica Corningstone', 'Brian Fantana'];echo $names[1];
Brick Tamland
To call a static method named randomize() in a class named Cart, you code
Cart::randomize()
If you code a column list in an INSERT statement that includes a column that's defined with a default value, you can insert the default value for that column by coding the ________________ keyword in the VALUES clause of the INSERT statement.
DEFAULT
Which of the following is NOT a SQL privilege for modifying the structure of a database?
DELETE
Which SQL statement can be used to delete a table?
DROP TABLE
The diff() method of a DateTime object requires another DateTime object as its argument and returns a/an ________________ object.
DateInterval
The use of ________________ objects resolves the Y2K38 problem because the upper limits of dates and times are essentially removed.
DateTime
If $today contains a DateTime object for December 25, 2021, what output would be produced by the code below? echo $today->format('F d, Y');
December 25, 2021
(Refer to code example 2-1) If this code is from the first page of this application, what does the if statement in the PHP tag do the first time this page is executed?
Doesn't do anything because $error_message will be empty
In a SELECT statement, the________________ clause specifies the table or tables to retrieve data from.
FROM
What does $message contain after the following code executes?$statusCode = "403";switch ( $statusCode ) {case "200": $message = "OK"; break;case "403": $message = "Forbidden"; break;case "404": $message = "Not Found"; break;default: $message = "Unknown Status"; break;}
Forbidden
To assign privileges to a user who has been defined for a database, you use the ________________ statement.
GRANT
When you pass arguments to a function by name, the named arguments
can appear anywhere in the argument list
One disadvantage of using mysqli is that it
can only be used with MySQL
Expressions coded in the HAVING clause
can use either aggregate search conditions or non-aggregate search conditions
If you want to code a catch block that catches all types of exceptions and gets the message associated with the exception, you start the catch block like this:
catch (Exception $e) {
Which type of input element should be used on a form when the user can select zero, one, or many of the options in a group?
checkbox
A static property or method is one that belongs to a/an ________________
class
At the start of a catch block in a try/catch statement, you code the name of the ________________ that defines the type of exception that the block is intended to catch.
class
A ________________ contains a value that does not change during the course of program execution.
constant
Which type of statement ends the current iteration of a loop?
continue
in the code that follows, if $error_message isn't empty if ($error_message != '') { include('index.php'); exit(); }
control is passed to a page named index.php that's in the current directory
