CPSC-431 Final Exam Study Guide Part 1/2

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

The __________ construct can be used to split an array into a number of values.

list()

PHP variables that are declared inside a function are known as:

local variables

In PHP you can have __________ catch block(s) associated with a single try block.

more than one

An array containing other arrays is known as a(n) ___________ array.

multidimensional

Which of the following is a valid MySQL connection command?

mysql -h dbserver -u joe -p

se the appropriate MySQL command to run the Total_Orders stored procedure, storing the results in the variable $t.

CALL Total_Orders($t);

Type the MySQL command used to define a new stored procedure

CREATE PROCEDURE

Create a MySQL user named milo with the password P@$$w0rd!

CREATE USER milo IDENTIFIED BY PASSWORD P@44w0rd!;

What is the definition of a relational database schema?

Complete set of table designs

Which of the following MySQL privileges allows users to remove databases, tables, or views?

DROP

What privilege is required for a MySQL database user to employ the LOAD DATA INFILE statement?

FILE

Which of the following is NOT a MySQL command used to gather more information about a given database?

GRANT

Give all privileges on all databases to the MySQL user fred. Make sure Fred can give database privileges to other users

GRANT ALL ON *.* TO fred WITH GRANT OPTION;

Edit the following code to accomplish the goal of reversing the array created by range(). $numbers = range(1,10); $numbers = ___($numbers);

$numbers = array_reverse($numbers);

Which of the following expressions shows a correct PHP array definition?

$products = ['Tires', 'Oil', 'Spark Plugs'];

Create an array (using full PHP syntax) named $products that contains the values gum, spam, and eggs.

$products = array('gum', 'spam', 'eggs');

Replace the first element of the $products array with Fuses

$products[0] = 'Fuses';

Edit the following PHP code to echo the value 4 to the browser. $test = "Hello world"; echo strpos($test, "___");

$test = "Hello world"; echo strpos($test, "o");

Assign the literal value 0.00 to the variable named $totalamount.

$totalamount = 0.00;

What is the result of the statement echo strlen("hello");?

5

Which of the following statements is false concerning PHP identifiers?

Identifiers are case insensitive

MySQL is an example of a(n):

RDBMS

Remove the SELECT privilege on the table toys from the MySQL user milo.

REVOKE SELECT ON toys FROM milo;

The ___________ MySQL statement allows a specified database user to grant his or her own privileges to others.

WITH GRANT OPTION

Which of the following is NOT a problem of working with flat files in PHP?

When a file becomes small, working with it can be very slow

Which of the following regex tokens anchors your match to the beginning of the subject string?

^

In object -oriented programming, __________ are properties or variables that relate to an object.

attributes

A(n) __________ shows which functions were executing at the time the exception was raised.

backtrace

Modify the following code to trap exceptions of the Exception class and store the results in the variable $e. catch (___ ___) { // handle exception }

catch (Exception $e) { // handle exception }

Modify the following code to specify that the B class is a subclass of the A class. class B ____ A { }

class B extends A { }

Edit the following PHP class definition to add a public attribute named attribute1. class MyClass { ______ }

class MyClass { public $attribute1; }

Make a call to a PHP function named compute by passing in the variable 42.

compute(42);

The PHP statement $a = new classname("First"); denotes a(n):

constructor

Create a database named toystore on the local MySQL server.

create database toystore;

A foreign key should have the same or comparable _________ as its related primary key.

data type

In a relational database table, each value must have the _____________ specified by its column.

data type

Which of the following is a PHP function used to declare constants?

define

What is the result of running the MySQL command EXPLAIN SELECT Customer, Balance FROM Customers;?

displays the query execution plan

Echo the string $hello world in such a way that the $hello variable's contents are interpolated into the output.

echo "$hello world";

Use PHP to echo the size of the file orders.txt that's present in your current working directory

echo filesize("orders.txt");

Use the _________ keyword to specify that one class is to be a subclass of another

extends

Use PHP to close the file $fp programmatically.

fclose($fp);

In PHP, a while loop tests for the end of the file by using which function?

feof()

Which of the following shows the correct use of the final PHP keyword?

final function operation() {}

The statement $products[0] accesses the ________ element in an array.

first

To open a file in PHP, you use the _________ function.

fopen()

The trim() function removes whitespace:

from the start and end of a string

Define a function named my_function that has no parameters and echoes the string function called

function my_function() { echo 'function called'; }

Write a function named table that accepts a parameter called data and echoes the string table created

function table($data) { echo 'table created'; }

Modify the following PHP function code to ensure that only the first echo statement is executed. Make your edit as compact as possible, using the blank underline as your guide. function test_return() { echo "This statement will be executed"; _____ echo "This statement will never be executed"; }

function test_return() { echo "This statement will be executed"; return; echo "This statement will never be executed"; }

Use the PHP fwrite function to write the string stored in $outputstring to the file pointed to by $fp.

fwrite($fp, $outputstring);

catch (Exception $e) { // handle exception }

getFile();

Which of the following is NOT a built -in method of the Exception PHP class?

getString()

Type the PHP Exception class's built-in method that returns an array containing a backtrace where the exception was raised.

getTrace();

What is the basic PHP library for connecting to MySQL?

mysqli

Create a namespace named orders to hold all your order-related PHP code.

namespace orders;

Which PHP function takes a string as a parameter and replaces all the newlines in it with the HTML <br/> tag?

nl2br()

Having many _________ values in your database wastes space and causes problems working out totals.

null

A primary key can consist of ___________ column(s).

one or more

What is the role of 'foo' in the PHP statement function('foo');?

parameter

Disable PHP from opening files via fopen() and FTP by editing:

php.ini

The object-oriented principle of ____________ means that different classes can have different behaviors for the same operation.

polymorphism

MySQL ____________ can speed up query execution as well as protect against SQL injection attacks.

prepared statements

Edit the following code to specify that $total is a floating point number with two decimal places after the decimal point. printf ("Total amount of order is ___", $total);

printf ("Total amount of order is %.2f", $total);

What is the default PHP class access modifier?

public

A PHP function that calls itself is known as a _________ function.

recursive

Use the PHP require statement to include the contents of the file reusable.php in your current script.

require('reusable.php');

In PHP it's considered good coding practice to implement _______ try blocks in your code.

small

Given the following $products definition, perform an ascending alphabetical sort on its contents. $products = array('Tires', 'Oil', 'Spark Plugs');

sort($products);

What is the purpose of the semicolon in PHP?

statement termination

The PHP keyword return:

stops the execution of a function

A(n) __________ is a programmatic function that is created and stored within MySQL.

stored procedure

Convert the $subject string to lowercase.

strtolower($subject);

Why is the query $query = "SELECT ISBN, Author, Title, Price FROM Book WHERE $searchtype = '$searchterm'"; problematic?

susceptible to SQL injection

Modify the following PHP code in such a way that you trigger the exception-handling mechanism. ___ new ___($message, $code);

throw new Exception($message, $code);

Which of the following shows the correct definition of a PHP exception?

throw new Exception($message, code);

In a PHP __________, you can group together functionality that may be reused in multiple classes.

trait

________________ are mechanisms for ensuring database consistency.

transactions

Use the appropriate MySQL command to list all columns from the Orders table in the books database

SHOW COLUMNS FROM books.Orders ;

Use the appropriate MySQL command to list all tables in the books database.

SHOW TABLES FROM books;

Use the appropriate MySQL command to list all tables in the current database.

SHOW TABLES;

What command is used to view all tables in the current MySQL database?

SHOW TABLES;

In PHP, the keyword __________ triggers the exception-handling mechanism.

throw

Which of the following PHP array operators signifies non-identity?

!==

Write a statement that accesses the contents of the field SERVER_NAME in an array variable named $_SERVER.

$_SERVER['SERVER_NAME']

Which of the following statements tests for equality between the PHP variables $a and $b?

$a == $b

Define a PHP variable named $c that is a copy of object $b of the same class with the same attribute values.

$c = clone $b;

Define an object named $c that instantiates an instance of the class MyClass, using no parameters.

$c = new MyClass();

Edit the following PHP code to split the customer's e-mail address into two parts. $email_array = ___(___, $email);

$email_array = explode('@', $email);

Which of the following PHP expressions can get the domain name from a customer's email address?

$email_array = explode('@', $email);

You need to open the file orders.txt for writing. Modify the following code, specifically the two placeholders, to accomplish your goal. $fp = ___("$document_root/orders.txt", '___');

$fp = fopen("$document_root/orders.txt", 'w');

Create a PHP array called $numbers with elements ranging from 1 to 10.

$numbers = range(1,10);

Which of the following represents the HTML encoding of >?

&gt;

Which of the following symbols represents a single-line comment in PHP?

//

Write a single-line PHP comment that says "Hello world"

//Hello world

Write a PCRE regular expression that matches http:// using http as a literal.

/http:\/\//

PHP indexes start at ________ by default.

0

Which of the following statements is true concerning PHP functions?

PHP function names cannot begin with a digit.

The expression $test = substr_replace($test, 'X', -1); replaces:

The last character in $test

How do you create a new MySQL database?

create database dbname;

Use the mysql command to log into a MySQL server named server01 with the username don and password P@$$w0rd!

mysql -h server01 -u don -p P@$$w0rd!

Modify the following PHP code such that it runs cleanly. ___ { // do something, maybe throw some exceptions } ___ (Exception $e) { // handle exception } ___ { echo 'Always runs!'; }

try { // do something, maybe throw some exceptions } catch (Exception $e) { // handle exception } finally { echo 'Always runs!'; }

You need to use a PHP while loop to read from a file until the end of the file is reached. Modify the following code to accomplish your goal. while (!___($fp))

while (!feof($fp))


Kaugnay na mga set ng pag-aaral

NUIP energy balance and with control

View Set