PHP Exam 1

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

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

In an if statement, the statements in the else clause are executed if none of the conditions in the if or ________________ clauses are true.

else if

The equality operator consists of two ________________ signs and performs a different function than the one performed by the assignment operator that consists of a single sign.

equal

SELECT vendorName, invoiceNumber, invoiceDate, invoiceTotal FROM vendors INNER JOIN invoices ON vendors.vendorID = invoices.vendorID WHERE invoiceTotal >= 500 ORDER BY vendorName DESC When you code an INSERT statement, you don't have to include the data for a column that

has a default value

The order of precedence for arithmetic expressions causes

increment operations to be done first

A(n) ________________ is a positive or negative number with no decimal places.

integer

When double quotes are used to assign values to string variables, the PHP interpreter must check the entire string to see if it contains any variables that need to be inserted into the string. This process is called:

interpolation

Which HTML tag or element is used to load an external stylesheet?

link

An inner join combines data from two or more tables in which the related fields ________________.

match

Which attribute of a form element determines how the data is passed to a file?

method

The ________________ operator divides one operand by another operand and returns the remainder.

modulus

The most common type of relationship between tables in a relational database is a ________________ relationship.

one-to-many

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

In an arithmetic expression, division is done before multiplication, but you can override that by using ________________.

parentheses

What is the concatenation operator in PHP?

period (.)

The ________________ key of a table uniquely identifies each record in the table.

primary

What does a relational database use to uniquely identify each row in a table?

primary keys

A web application starts when a client sends a/an ________________ to a server.

request

To view the source code for a web page in a web browser, you can display the View Source command by

right-clicking on the page

A table in a relational database consists of columns and ________________.

rows

phpMyAdmin can be used to import and run a SQL ________________ that creates one or more databases.

script

To deploy a PHP application on your own computer, you copy the application root directory to

the htdocs directory of the Apache server

The result set retrieved by the following SELECT statement contains rows that have SELECT balance, number FROM accounts WHERE balance < 0

two of the columns from the accounts table where balance is less than 0

A variable name in PHP can only contain letters, numbers, and ________________.

underscores

To run a PHP application that has been deployed on your own computer, you can enter a URL in the address bar of your browser that

uses localhost as the domain name

To get the data that is submitted with an HTTP GET request, you use PHP to get the data from the built-in ________________ array.

$_GET

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

Which character is used to separate parameters that are appended to a URL?

&

The following is a compound assignment operator in PHP?

+= -+ %=

What extension of a filename is typically associated with a static Web page?

.htm

Which clause in a SQL statement is typically used to return data from more than one table?

JOIN

In a conditional expression that includes logical operators, the AND operator has a lower order of precedence than the ________________ operator.

NOT

Assigning ________________ to a variable indicates the variable does not contain a usable value.

NULL

Which clause in a SQL statement specifies how the result set should be sorted?

ORDER BY

The ________________ extension to PHP defines an interface for accessing databases.

PDO

Which PHP class can be used to connect to a MySQL database?

PDO

Which of the following is a class used for errors thrown by the PDO library?

PDOException

In the catch block of a try/catch statement for handling PDO exceptions, you can get a message that describes the exception by using the getMessage() method of the

PDOException object

Which of the following software components generates the HTML that is returned in an HTTP response?

PHP

When the web server receives an HTTP request for a PHP page, the web server calls the

PHP interpreter

Which method of the form passes data without appending the parameters to the URL?

POST

Which clause in a SQL statement specifies the columns to return?

SELECT

Which type of SQL statement returns a result set?

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

A join that returns records from related tables only if their related fields match is called

an inner join

When you call a function like the number_format() function that returns a value, you usually ________________ the result of the function to a variable.

assign

It's considered a best practice to always use the ________________ function when you get values from a superglobal array.

filter_input

To access the data for all of the rows in a result set that's returned by a SELECT statement, you can use a ________________ loop.

foreach

Which of the following can be used to get the data from an array that contains all rows of a result set?

foreach statement

What does a relational database use to relate the tables in a database to other tables?

foreign keys

When you ________________ a request, all processing takes place on the server.

forward

When you ________________ an HTTP request, all processing takes place on the server before the response is returned to the browser.

forward

The HTTP response for a dynamic web page is passed

from the web server to the browser

When you code a function in PHP, you start with the ________________ keyword.

function

To make a variable that is declared outside of a function usable inside the PHP function, which keyword can be used?

global

To make a variable that's declared outside a function available to the function, you must code the ________________ keyword.

global

Which of the following is an object that contains information about an error that occurred?

handler

To control what users can do with a database, SQL can be used to create users and assign ________________ to them.

privileges

The first part of a URL is called the

protocol

When you ________________ a request, the server returns a response that tells the browser to request another URL.

redirect

Which of the following is a term that refers to modifying the organization or structure of an application?

refactoring

If many different files may load an external file, what statement can be used instead of 'include' to make sure the external file is only loaded once?

require_once

To pass data back to the statement that calls a function, the function can use the ________________ statement.

return

Which type of statement should be included if the function should send a value back to where the function was called?

return

How many data types are used by PHP?

six

A ________________ web page is one that has .html or .htm as its extension.

static

When HTML was first developed, Web pages were typically

static

Which of the following is NOT a benefit of using the MVC pattern for an application?

the application runs more efficiently

When you use the MVC pattern, the controller gets the HTTP requests and then directs the use of the files that represent

the model and the view

To handle exceptions, first you code a/an ________________ around any PHP statements that might throw an exception.

try block

To handle the PDO exceptions that can occur when database methods are executed, you use a ________________ statement.

try/catch

When you use the MVC pattern, the ________________ consists of the HTML and PHP files that make up the user interface of the application.

view

Which of the following consists of the PHP and HTML files that represent the user interface of an application?

view

In PHP, all variables begin with a

$

The variables in PHP are easy to spot because they always start with ________________.

$

Which of the following can be used to style a label in an id named data?

#data label

After the code that follows is executed, what will the value of $units_per_store be? $units = 30; $stores = 4; $units_per_store = $units % $stores;

2

If a PHP array contains 7 elements, what is the number of the index of the seventh element?

6

Which of the following is software that is a Web server?

Apache

________________ is the web server that is commonly used for web applications that are written in PHP.

Apache

A ________________ value is a value of true and false.

Boolean

What is a common MySQL data type?

CHAR VARCHAR INT

The ________________ for a MySQL connection specifies the host computer for the MySQL database and the name of the database.

DSN(Data Source Name)

Which clause in a SQL statement specifies the table(s) that should supply the data that is returned?

FROM

Which clause in a SQL statement specifies the records to return based on criteria?

WHERE

When you use the header() function to redirect a request,

a response is returned to the browser that tells it to request another page

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

An index for a PHP array:

can be a number or a string

Which of the following receives requests from users, gets the appropriate data, and returns the appropriate views to the users?

controller

When coding relative URLs, you can begin the URL with a single dot (.) to indicate that the URL should start with the ________________ directory.

current

When you use the MVC pattern, the model consists of the PHP files that work with and represent the ________________ of the application.

data

A/An ________________ is an object that contains information about an error.

exception

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

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

Which function can be used to redirect a request to another URL?

header()

Which URL can be used to start phpMyAdmin on a local system?

http://localhost/phpmyadmin

Which function can be used to forward a request from one PHP file to another?

include()

To access one of the elements in an array, you code the array name and a set of brackets that contains the ________________ of the element you want to access.

index

To refer to the elements in an array, you use a string, or numeric ________________.

index

One reason for using the header() function to redirect a request

is to have a PHP file run itself again

When you use the MVC pattern, you

make each layer as independent as possible

Which of the following consists of the PHP files that represent the data of the applications?

model

To create a PDO object, you code the ________________ keyword, followed by PDO, followed by the three arguments that it requires.

new

Which keyword is used to create an object from a class in PHP?

new

To call a function in PHP, you code the function name followed by a list of any ________________ that are required.

parameters

When creating a function, ________________ can be included in the parentheses that follow the name.

parameters

When you code a function in PHP, you can list one or more ________________ that must be passed to the function.

parameters

Each row in a table should be able to be uniquely identified by a

primary key

You use a SQL ________________ statement to retrieve data from a SQL database.

SELECT

<h1>Future Value Calculator</h1> <?php if (!empty($error_message)) { ?> <p class="error"><?php echo $error_message; ?></p> <?php } ?> <form action="display_results.php" method="post"> <div id="data"> <label>Investment Amount:</label> <input type="text" name="investment" value="<?php echo $investment; ?>"/><br /> <label>Yearly Interest Rate:</label> <input type="text" name="interest_rate" value="<?php echo $interest_rate; ?>"/><br /> <label>Number of Years:</label> <input type="text" name="years" value="<?php echo $years; ?>"/><br /> </div> (Refer to code example 2-1) If this code is from the first page of this application, what do the three <input> tags display the second time this page is executed?

Text boxes that contain the data the user entered the first time the page was displayed

If $total_months has a value of 13, what does $message contain after this if statement is executed? $years = $total_months / 12; $years = number_format($years); $months = $total_months % 12; if ( $years == 0 ) { $message = $months . " months"; } else if ( $months == 0 ) { $message = $years . " years"; } else { $message = $years . " years, and " . $months . " months"; }

1 years, and 1 months

What will $future_value contain after the for loop that follows has been executed one time? $years = 10; $annual_rate = 10; $future_value = 1000; $annual_rate = $annual_rate / 100; for ( $i = 1; $i <= $years; $i++ ) { $future_value = $future_value * (1 + $annual_rate); }

1100

SELECT vendorName, invoiceNumber, invoiceDate, invoiceTotal FROM vendors INNER JOIN invoices ON vendors.vendorID = invoices.vendorID WHERE invoiceTotal >= 500 ORDER BY vendorName DESC How many columns will the result set have?

4

After the if statement that follows is executed, what will the value of $discount_amount be? $discount_amount; $order_total = 200; if ($order_total > 200) { $discount_amount = $order_total * .3; } else if ($order_total > 100) { $discount_amount = $order_total * .2; } else { $discount_amount = $order_total * .1; }

40

After the code that follows is executed, what will the value of $units_per_store be? $units = 30; $stores = 4; $units_per_store = intdiv($units, $stores);

7

To embed PHP within HTML, you start a tag with ________________, you code the embedded PHP statements, and you end the tag with ?>.

<?php

In a simple assignment statement, you code the variable name followed by the ________________ operator.

=

Which of the following is considered the assignment operator in PHP?

=

Which character is used to separate the original URL from the parameters that are appended to it?

?

A PHP variable name

A variable starts with the $ sign, followed by the name of the variable A variable name must start with a letter or the underscore character A variable name cannot start with a number A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ ) Variable names are case-sensitive ($age and $AGE are two different variables)

________________ are used in PHP to perform mathematical calculations, such as addition.

Arithmetic operators

To add a row to a table in a database, you use the SQL ________________ statement.

INSERT

Which of the following is NOT a common MySQL privilege?

INSERT TABLE

________________ operators are used for combining conditional expressions.

Logical

Which of the following can a SELECT statement NOT do to the data in a table?

Delete the rows

<h1>Future Value Calculator</h1> <?php if (!empty($error_message)) { ?> <p class="error"><?php echo $error_message; ?></p> <?php } ?> <form action="display_results.php" method="post"> <div id="data"> <label>Investment Amount:</label> <input type="text" name="investment" value="<?php echo $investment; ?>"/><br /> <label>Yearly Interest Rate:</label> <input type="text" name="interest_rate" value="<?php echo $interest_rate; ?>"/><br /> <label>Number of Years:</label> <input type="text" name="years" value="<?php echo $years; ?>"/><br /> </div> 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

Which method of the form appends values to the URL to pass data?

GET

What type of SQL statement is used to assign user privileges in MySQL?

GRANT

What type of a request does a Web browser typically send to a server?

HTTP

URL stands for

Uniform Resource Locator

You can use the htmlspecialchars() function to protect against ________________.

XSS attacks

SELECT vendorName, invoiceNumber, invoiceDate, invoiceTotal FROM vendors INNER JOIN invoices ON vendors.vendorID = invoices.vendorID WHERE invoiceTotal >= 500 ORDER BY vendorName DESC When you code a DELETE statement, you usually need to include

a WHERE clause

A request and response for a file are made by

a client and a server

If a URL specifies a directory that doesn't contain a default page, Apache displays

a list of all of the directories in that directory

SELECT vendorName, invoiceNumber, invoiceDate, invoiceTotal FROM vendors INNER JOIN invoices ON vendors.vendorID = invoices.vendorID WHERE invoiceTotal >= 500 ORDER BY vendorName DESC If vendorName contains string data and invoiceTotal contains decimal values, how will the result set be ordered?

alphabetically starting with Z

In HTML, parameters are called

attributes

To make it easier to enter names into your code, NetBeans provides a feature known as

auto-completion

The condition for a while loop is tested ________________ the statements in the loop are executed.

before

The ________________ data type is used to store a true or false value.

boolean

Google Chrome is a ________________.

browser

In a web application, the client uses a ________________ to interact with a web server.

browser

A web application is a type of

client/server application

The ________________ in a block of PHP code are ignored.

comments

A ________________ contains a value that does not change during the course of program execution.

constant

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

The ________________ of a column in a database table determines what type of data can be stored in the column.

data type

If you omit the filename from a URL, the Apache web server displays a list of files and directories if the specified directory doesn't contain a ________________ such as index.php.

default file

To deploy a PHP application on your own server, you copy or move its ________________ to the document root directory of the Apache server.

directory

In an HTTP URL, the ________________ is coded immediately after the protocol but before the path.

domain

To use PHP to send data to the browser, you use the ________________ statement.

echo

To print a variable with the echo statement, you simply pass the variable name to the echo statement. For example:

echo $VotingAge;

SELECT vendorName, invoiceNumber, invoiceDate, invoiceTotal FROM vendors INNER JOIN invoices ON vendors.vendorID = invoices.vendorID WHERE invoiceTotal >= 500 ORDER BY vendorName DESC What table(s) does the data in the result set come from?

vendors and invoices

A ________________ makes websites available to other computers over a network.

web server

In a PHP application, dynamic web pages are generated by PHP scripts that are running on the ________________.

web server

The column definition for a MySQL table can be used to determine

what type of data the column can contain whether the column can contain a null value whether the column has a default value


Set pelajaran terkait

Chapter 22: Integumentary System

View Set

Intermediate Accounting 3 - Exam 1 (Ch 15 & 16)

View Set

Chapter 47: Management of Patients With Intestinal and Rectal Disorders 4

View Set

Cognition: Exploring the Science of the Mind (7E), Daniel Reisberg, Chapter 7

View Set

Religion The Sacraments:chapter 2

View Set