Test Midterm Spring 2006 Sample
Instructions: This is a closed book, notes, neighbor examination. Select
the best answer. All output is to be considered what appears in the
browser. DO write on the examination.
- What is returned by the mysql_query() function?
- True or False
- a result identifier
- A and B
- the result set of data
- None of the above
- Which statement is false?
- PhP uses a plethora of specialized function calls that are useful only for certain databases and not others.
- Interbase is the name of an open source database product.
- Postgres is the name of a free database product.
- msql_affected_rows is a function that returns the number of rows involved in querying a mysql database.
- None of the above
- What gets printed with the following code:
<?php
$var1 = 2;
$var3 = 10;
$var4 = 20;
function fn ($arg1, &$arg2) {
global $var2;
$var1 = 4;
$var2 = 3;
$arg1 = 12;
$arg2 = 22;
}
echo 'Before: ' . "'$var1'" . ', ' . "'$var2'" . ', ' . "'$var3'" . ', ' . "'$var4'" . "<br />n";
fn ($var3, $var4);
echo 'After: ' . "'$var1'" . ', ' . "'$var2'" . ', ' . "'$var3'" . ', ' . "'$var4'" . "<br />n";
?>
- Before: '2', '', '10', '20'
After: '4', '3', '10', '22'
- Before: '2', '3', '10', '20'
After: '2', '3', '12', '22'
- Before: '2', '', '10', '20'
After: '2', '', '10', '20'
- Before: '2', '', '10', '20'
After: '2', '3', '10', '22'
- None of the above
- What is a valid name of a variable?
- _7variable
- 7variable
- variable-1
- ~variable
- None of the above
- Will this code generate a parse error?
<?php
$recordID = 135;
$query = "SELECT notes FROM customers WHERE id = " . $recordID ;
$result = mysql_query($query,$dbc);
while($row = mysql_fetch_array($result,1)) {
$outputNote= $row['notes'] ;
}
?>
- No, I won't work, Syntax is incorrect.
- Yes, It will work, Syntax is correct.
- I don't know for sure.
- "While" is not a valid PHP key word.
- None of the above
- What does the "@" sign signify when opening a mySQL database or table?
- refers to default index pointer
- checks valid email address data type
- supresses system error message
- calls email varification function
- None of the above
- What gets printed by the following code:
<?php
$Today = Date ("l F d, Y");
print ($today);
?>
- Today's date formatted as in "Wednesday Jan 25, 2006"
- Nothing - "date" function name must be all lowercase
- Today's date formatted as in "Wednesday January 25, 2006"
- Nothing - printed variable "$today" does not match case of assigned variable "$Today"
- None of the above
- What does this code output?
<?php
$a = 1.50 ;
$b = 2 ;
print("$a * $b");
print("<br>");
print($a * $b);
?>
- 1.5 * 2
3
- 3
3
- 1.5
2
- 1.5 * 2
1.5 * 2
- None of the above
- What does the following code output?
<?php
$alpha = array("it's ","lost ","assignments ");
$beta = array("points.",".2 ","killing ");
$gamma = array("Late ","I've ","Ouch, ");
$delta = array("me.","loose ","20%.");
$i=0;
for($i; $i<3; $i++){
print $gamma[$i];
print $alpha[2-$i];
switch ($i) {
case 0:
print $delta[1];
break;
case 1:
print $beta[1];
break;
case 2:
print $beta[2];
break;
}
if ($i== 0) {
print $delta[2];
} elseif ($i== 1) {
print $beta[0];
} else {
print $delta[0];
}
print "<BR />";
}
?>
- Late assignments loose 20%.
- I've lost .2 points.
- Ouch, it's killing me.
- All of the above
- None of the above
- You will get a value of 1 when you cast an array as a
- boolean
- integer
- string
- "a" and "b" only
- None of the above
- In PHP, the signature of a function is:
- Determined by the type of the arguments
- Determined by the type of the data returned by the function
- Determined by the name of the function
- Non-existent
- None of the above
- Which piece of PHP code will generate an error?
- $query = "SELECT * FROM registration ORDER BY 'id' ";
- include("mysql_connect.php");
- $address = $_POST['address'];
- $message = "<p>Log In failed due to system error on Server" 2". <br />Please try again!.</p>";
- None of the above
- What does the following function do?
function myFunc($filename) {
ob_start();
$handle = fopen ($filename, "r");
fpassthru($handle);
$output = ob_get_contents();
ob_end_clean();
return $output;
}
- Prints the contents of a file to output.
- Buffers the output of the contents of a file then prints the contents to output.
- Returns the contents of a file as an array where each line is an element in the array,
- Returns the contents of a file as a string.
- None of the above
<?php
$temp;
?>
<html>
<head><title>XYZ</title></head>
<body>
<?php
$temp = "xyz";
print ("temp is $temp");
?>
</body>
</html>
- temp in the php blocks are independent of each other
- temp in the php blocks is the same variable
- temp in the first php block is a global variable
- temp in the second php block is a local variable.
- None of the above
- What group of
function calls would you use to programmatically determine the names of
the columns in a database table? You can assume that you have already
connected to the server and selected the database containing the table.
- mysql_query and mysql_fetch_field
- mysql_query and mysql_fetch_object
- mysql_list_fields, mysql_num_fields, and mysql_field_name
- Either A or C
- None of the above
- Four functions control PHP's output buffer: Which one of the below is NOT a PHP Buffer?
- ob_end_clean
- ob_get_contents
- ob_end_flush
- ob_get_started
- None of the above
<?php
// Show the output of the following code:
// This is array 1 ...
$array1 = array(-1 => 21, 34, 43, 54, 4 => 65);
echo $array1[2];
// This is array 2 ...
$array2 = array(0 => 21, 34, 43, 3 => 54, 65);
echo $array2[2];
// This is array 3 ...
$array3 = array(0 => 21, -1 => 34, 43, 54, 65);
echo $array3[1];
// This is array 4 ...
$array4 = array(21, -1 => 34, 43, 54, 65);
echo $array4[0];
?>
- 43435421
- 54435421
- 43435443
- 54434321
- None of the above
- In a single-Dminesional array how would you refer to an element.
- {}
- <>
- """"
- []
- None of the above
<?php
$food = array ("seafood" => array ('tuna', 'shrimp', 'crab'),
"meat"
=> array ('beef', 'chicken', 'turkey'));
echo $food["meat"][1];
?>
Each of the following is true about the above code except:
- $food is a 2 dimensional array
- $food["meat"][1] accesses 'chicken'
- $food[1]["meat"] accesses 'chicken'
- $food is an array with 2 rows and 3 columns
- None of the above
<body>
<p>For the following variables w, x, y, and z, fill in the<br />
table created by script below:</p>
<table border="1" cellpadding="5">
<tr>
<th>w</th>
<th>x</th>
<th>-y</th>
<th>z</th>
</tr>
<?php
$y = 1;
$x = 3 + $y;
for ( $w=0; $w < $x; $w++ ) {
$y = -2;
$z = ($x - $w) + $y;
?>
<tr>
<td><?php echo $w; ?></td>
<td><?php echo $x; ?></td>
<td><?php echo -$y; ?></td>
<td><?php echo $z; ?></td>
</tr>
<?php
}
?>
</table>
- w x -y z
0 1 -1 -1
1 1 -1 -2
- w x -y z
0 4 2 6
1 4 2 5
2 4 2 4
3 4 2 3
- w x -y z
0 4 -2 6
1 4 -2 5
2 4 -2 4
3 4 -2 3
w x -y z
0 4 2 2
1 4 2 1
2 4 2 0
3 4 2 -1
- None of the above
- Which statement is false?
- You can cast an array to an integer.
- PHP won't promote an array to an object.
- The => operator is used to create multidimensional arrays.
- All strings can be referenced as arrays.
- None of the above
- Which function returns an array?
mysql_fetch_arry(...)
mysql_fetch_row(...)
mysql_fetch_assoc(...)
- All of the above
- None of the above
- The PHP data type "Resource" are ...
- a boolean
- an integer
- a string
- a float
- None of the above
- An array may be created by....
- An array may only be created with the "array()" function.
- An array may only be created with the array operator [].
- An array may only be created with the array operand [].
- An array may only be created with the array () operator.
- None of the above
- Complete the following statement correctly.
PHP started as a simple ______________________.
- macro replacement tool
- server side editor
- extension to Apache
- all of the above complete the statement correctly.
- None of the above
- Which of the following is true? When declaring a function, you may...
- Declare multiple argument inside parenthesis separated by a space.
- Declare multiple arguments inside parenthesis if they are separated by commas.
- Use quotes around the argument.
- Declare the argument with a dollar sign use quotes.
- None of the above
- PHP works with
- IIS -- Internet Information Server
- Apache Web Server
- WebTen Web Server
- All of the above
- None of the above
<?php
$golly = "date";
$HiOpie = $golly("G");
print("<h1>$HiOpie</h1>");
?>
- renders as a line from the Andy Griffith show
- displays the hour in 24-hour format without leading zeros
- displays the hour in 24-hour format with leading zeros
- B and C are both true
- None of the above
- Another way to
stop execution of the function is to use the return statement. You may
have multiple return statements in your function.
- True
- False
- In the body of
a for statement, suppose you want control to skip to the closing curly
brace at the end of the body so that the "increment" portion of the for
statement is executed next. What statement would you use to accomplish
this?
- skip
- break
- continue
- return
- None of the above
- To send and expression to the browser before aborting the code use the following:
- exit
- die
- return
- break
- None of the above
- Which character precedes a variable in PHP?
- #
- @
- $
- %
- None of the above
- Which of the following statement pairs about cookies and sessions are true? (i.e. both statements are true)
- 1.
Cookies are widely regarded by the site viewing public as harmless,
consequently browser developers do not allow them to be disabled.
2. Sessions work even if cookies have been disabled.
- 1. Cookies store data on a web browser.
2. Sessions store data on a web browser.
- 1. The call to "session_start();" is made to initiate a session or join an existing session.
2. There are no functions for setting cookies as these are sent automatically by the server to the browser.
- 1.
A cookie is a name/value pair associated with a particular website, and
is stored on the computer that runs the client browser.
2. If cookies are disabled, PHP session IDs can be added as query
string variables to all relative links on all site pages, even if some
are .html and are not .php pages.
- None of the above
- What will the following code output?
<?php
$s1 = "Hello, ";
$s2 = "world!";
$s3 = &$s1;
$s1 .= $s2;
print("$s3\n");
?>
- Hello,
- world!
- Hello, world!
- s3
- None of the above
- What does the expression
(10 & 7) evaluate to?
- 17
- 1
- 2
- 3
- None of the above
- PHP functions are prohibited from returning which data type?
- integer.
- float.
- string.
- boolean.
- None of the above
- Which of the following databases does PHP not handle?
- informix
- MyQSL
- Oracle
- Sybase
- None of the above
- Which function returns the numerical value of the error message from previous MySQL operation.
$error = mysql_errno(...);
$error = mysql_errnum(...);
$error = mysql_errono(...);
$erro = mysql_error(...);
- None of the above
- What does the acronym CRUD stand for?
- Crazy Rude Uptight Drivers
- the basic functions of a database in computing:
Create, Read, Update, Delete
- stuff you can get stuck to your shoe
- stuff found in your kitchen drain
- None of the above
- All of the following are relational databases supported by PHP except:
- MySQL
- Informix
- Oracle
- ODBC
- None of the above
- What is recursion?
- When you have two functions calling each other.
- When you have a function that calls itself.
- When your program gets stuck in an infinite loop.
- When you pass a variable by reference to a function.
- None of the above
- What is the correct syntax for a PHP script?
<?php>
print (date("Y"));
</php?>
// print (date("Y"));
<@ php
print (date("Y"));
@>
<?
print (date("Y"));
- None of the above
- What does this code display in the browser?
<?php
$test = 17.37;
echo gettype($test);
?>
- float
- string
- boolean
- double
- None of the above
- What gets printed with the following code:
<?php
$var1 = 10;
$var2 = "20.6text";
$var1 += $var2;
print ($var1);
?>
- 10
- 30.6
- 31
- 30
- None of the above
- Which constant is used in the mysql_fetch_array(...) function?
- MYSQL_ASSOC?
- MYSQL_BOTH?
- MYSQL_NUM?
- All of the above
- None of the above
- What is the output of this code?
<?php
$aa = 4;
test($aa);
function test($aa) {
print ("one: $aa<br />\n");
$aa++;
print ("two: $aa<br />\n");
}
print ("three: $aa<br />\n");
?>
- one: 4
two: 5
three: 5
- one: 4
two: 4
three: 4
- one: 5
two: 5
three: 5
- one: 4
two: 5
three: 4
- None of the above
- $returnCode = mysql_errno();
- Does nothing if MySQL has not encountered an error.
- Sets variable $returnCode to an integer representing the number of errors in the last database accessed.
- Sets variable $returnCode to a string value containing an error number from MySQL.
- Sets variable $returnCode to an integer representing the error number of the previous MySQL function call.
- None of the above
- In an argument which one of the below lines of code will fetch one argument at a time.
- func_num_args
- func_get_args
- func_get_one
- func_get_arg
- None of the above
- The operator >> means:
- MUCH greater than
- Tab twice to the right
- Shift all bits to the right
- Important Comment!
- None of the above
- What is the output of this code?
<?php
print("<table border="1">\n");
for($Row=1; $Row<=12; $Row++) {
print("<tr>\n");
for($Column=1; $Column<=12; $Column++) {
print("<td>");
print($Row * $Column);
print("<td>");
}
print("<tr>\n");
}
print("</table>\n");
?>
- a 12 row table
- which browser someone is using to surf your page
- an empty grid with rows and columns
- a multiplication table
- None of the above
- A session is only valid on a single server.
- True
- False
- Don't know.
- Statement is incorrect.
- None of the above
- What is a reason for an internet server provider (ISP) to support PHP?
- There's less risk to the server with PHP applications than with CGIs.
- Microsoft provides excellent support for PHP.
- PHP is very similar to Visual Basic and so is very easy to use.
- All of the above
- None of the above