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.

  1. What is returned by the mysql_query() function?
    1. True or False
    2. a result identifier
    3. A and B
    4. the result set of data
    5. None of the above

  2. Which statement is false?
    1. PhP uses a plethora of specialized function calls that are useful only for certain databases and not others.
    2. Interbase is the name of an open source database product.
    3. Postgres is the name of a free database product.
    4. msql_affected_rows is a function that returns the number of rows involved in querying a mysql database.
    5. None of the above

  3. 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";

    ?>
    1. Before: '2', '', '10', '20'
      After: '4', '3', '10', '22'
    2. Before: '2', '3', '10', '20'
      After: '2', '3', '12', '22'
    3. Before: '2', '', '10', '20'
      After: '2', '', '10', '20'
    4. Before: '2', '', '10', '20'
      After: '2', '3', '10', '22'
    5. None of the above

  4. What is a valid name of a variable?
    1. _7variable
    2. 7variable
    3. variable-1
    4. ~variable
    5. None of the above

  5. 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'] ;
        }
    ?>

    1. No, I won't work, Syntax is incorrect.
    2. Yes, It will work, Syntax is correct.
    3. I don't know for sure.
    4. "While" is not a valid PHP key word.
    5. None of the above

  6. What does the "@" sign signify when opening a mySQL database or table?
    1. refers to default index pointer
    2. checks valid email address data type
    3. supresses system error message
    4. calls email varification function
    5. None of the above

  7. What gets printed by the following code:
    <?php
        $Today = Date ("l F d, Y");
        print ($today);
    ?>
    1. Today's date formatted as in "Wednesday Jan 25, 2006"
    2. Nothing - "date" function name must be all lowercase
    3. Today's date formatted as in "Wednesday January 25, 2006"
    4. Nothing - printed variable "$today" does not match case of assigned variable "$Today"
    5. None of the above

  8. What does this code output?
    <?php
        $a = 1.50 ;
        $b = 2 ;
        print("$a * $b");
        print("<br>");
        print($a * $b);
    ?>


    1. 1.5 * 2
      3
    2. 3
      3
    3. 1.5
      2
    4. 1.5 * 2
      1.5 * 2
    5. None of the above

  9. 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 />";
        }
    ?>
    1. Late assignments loose 20%.
    2. I've lost .2 points.
    3. Ouch, it's killing me.
    4. All of the above
    5. None of the above

  10. You will get a value of 1 when you cast an array as a
    1. boolean
    2. integer
    3. string
    4. "a" and "b" only
    5. None of the above

  11. In PHP, the signature of a function is:
    1. Determined by the type of the arguments
    2. Determined by the type of the data returned by the function
    3. Determined by the name of the function
    4. Non-existent
    5. None of the above

  12. Which piece of PHP code will generate an error?
    1. $query = "SELECT * FROM registration ORDER BY 'id' ";
    2. include("mysql_connect.php");
    3. $address = $_POST['address'];
    4. $message = "<p>Log In failed due to system error on Server" 2". <br />Please try again!.</p>";
    5. None of the above

  13. 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;
    }
    1. Prints the contents of a file to output.
    2. Buffers the output of the contents of a file then prints the contents to output.
    3. Returns the contents of a file as an array where each line is an element in the array,
    4. Returns the contents of a file as a string.
    5. None of the above


  14. <?php
        $temp;
    ?>

    <html>
    <head><title>XYZ</title></head>
    <body>
    <?php
        $temp = "xyz";
        print ("temp is $temp");
    ?>
    </body>
    </html>
    1. temp in the php blocks are independent of each other
    2. temp in the php blocks is the same variable
    3. temp in the first php block is a global variable
    4. temp in the second php block is a local variable.
    5. None of the above

  15. 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.
    1. mysql_query and mysql_fetch_field
    2. mysql_query and mysql_fetch_object
    3. mysql_list_fields, mysql_num_fields, and mysql_field_name
    4. Either A or C
    5. None of the above

  16. Four functions control PHP's output buffer: Which one of the below is NOT a PHP Buffer?
    1. ob_end_clean
    2. ob_get_contents
    3. ob_end_flush
    4. ob_get_started
    5. None of the above

  17. <?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];

    ?>
    1. 43435421
    2. 54435421
    3. 43435443
    4. 54434321
    5. None of the above

  18. In a single-Dminesional array how would you refer to an element.
    1. {}
    2. <>
    3. """"
    4. []
    5. None of the above

  19. <?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:
    1. $food is a 2 dimensional array
    2. $food["meat"][1] accesses 'chicken'
    3. $food[1]["meat"] accesses 'chicken'
    4. $food is an array with 2 rows and 3 columns
    5. None of the above

  20. <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>
    1. w x -y z


      0 1 -1 -1


      1 1 -1 -2
    2. w x -y z


      0 4 2 6


      1 4 2 5


      2 4 2 4


      3 4 2 3
    3. w x -y z


      0 4 -2 6


      1 4 -2 5


      2 4 -2 4


      3 4 -2 3

    4. w x -y z


      0 4 2 2


      1 4 2 1


      2 4 2 0


      3 4 2 -1
    5. None of the above

  21. Which statement is false?
    1. You can cast an array to an integer.
    2. PHP won't promote an array to an object.
    3. The => operator is used to create multidimensional arrays.
    4. All strings can be referenced as arrays.
    5. None of the above

  22. Which function returns an array?
    1. mysql_fetch_arry(...)
    2. mysql_fetch_row(...)
    3. mysql_fetch_assoc(...)
    4. All of the above
    5. None of the above

  23. The PHP data type "Resource" are ...
    1. a boolean
    2. an integer
    3. a string
    4. a float
    5. None of the above

  24. An array may be created by....
    1. An array may only be created with the "array()" function.
    2. An array may only be created with the array operator [].
    3. An array may only be created with the array operand [].
    4. An array may only be created with the array () operator.
    5. None of the above

  25. Complete the following statement correctly.

    PHP started as a simple ______________________.
    1. macro replacement tool
    2. server side editor
    3. extension to Apache
    4. all of the above complete the statement correctly.
    5. None of the above

  26. Which of the following is true? When declaring a function, you may...
    1. Declare multiple argument inside parenthesis separated by a space.
    2. Declare multiple arguments inside parenthesis if they are separated by commas.
    3. Use quotes around the argument.
    4. Declare the argument with a dollar sign use quotes.
    5. None of the above

  27. PHP works with
    1. IIS -- Internet Information Server
    2. Apache Web Server
    3. WebTen Web Server
    4. All of the above
    5. None of the above

  28. <?php
        $golly = "date";
        $HiOpie = $golly("G");
        print("<h1>$HiOpie</h1>");
    ?>
    1. renders as a line from the Andy Griffith show
    2. displays the hour in 24-hour format without leading zeros
    3. displays the hour in 24-hour format with leading zeros
    4. B and C are both true
    5. None of the above

  29. Another way to stop execution of the function is to use the return statement. You may have multiple return statements in your function.
    1. True
    2. False

  30. 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?
    1. skip
    2. break
    3. continue
    4. return
    5. None of the above

  31. To send and expression to the browser before aborting the code use the following:
    1. exit
    2. die
    3. return
    4. break
    5. None of the above

  32. Which character precedes a variable in PHP?
    1. #
    2. @
    3. $
    4. %
    5. None of the above

  33. Which of the following statement pairs about cookies and sessions are true? (i.e. both statements are true)
    1. 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.
    2. 1. Cookies store data on a web browser.
      2. Sessions store data on a web browser.
    3. 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.
    4. 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.
    5. None of the above

  34. What will the following code output?
    <?php
        $s1 = "Hello, ";
        $s2 = "world!";
        $s3 = &$s1;
        $s1 .= $s2;
        print("$s3\n");
    ?>
    1. Hello,
    2. world!
    3. Hello, world!
    4. s3
    5. None of the above

  35. What does the expression (10 & 7) evaluate to?
    1. 17
    2. 1
    3. 2
    4. 3
    5. None of the above

  36. PHP functions are prohibited from returning which data type?
    1. integer.
    2. float.
    3. string.
    4. boolean.
    5. None of the above

  37. Which of the following databases does PHP not handle?
    1. informix
    2. MyQSL
    3. Oracle
    4. Sybase
    5. None of the above

  38. Which function returns the numerical value of the error message from previous MySQL operation.
    1. $error = mysql_errno(...);
    2. $error = mysql_errnum(...);
    3. $error = mysql_errono(...);
    4. $erro = mysql_error(...);
    5. None of the above

  39. What does the acronym CRUD stand for?
    1. Crazy Rude Uptight Drivers
    2. the basic functions of a database in computing:


      Create, Read, Update, Delete
    3. stuff you can get stuck to your shoe
    4. stuff found in your kitchen drain
    5. None of the above

  40. All of the following are relational databases supported by PHP except:
    1. MySQL
    2. Informix
    3. Oracle
    4. ODBC
    5. None of the above

  41. What is recursion?
    1. When you have two functions calling each other.
    2. When you have a function that calls itself.
    3. When your program gets stuck in an infinite loop.
    4. When you pass a variable by reference to a function.
    5. None of the above

  42. What is the correct syntax for a PHP script?
    1. <?php>
      print (date("Y"));
      </php?>
    2. // print (date("Y"));
    3. <@ php
      print (date("Y"));
      @>
    4. <?
      print (date("Y"));
    5. None of the above

  43. What does this code display in the browser?
    <?php
        $test = 17.37;
        echo gettype($test);
    ?>
    1. float
    2. string
    3. boolean
    4. double
    5. None of the above

  44. What gets printed with the following code:
    <?php
        $var1 = 10;
        $var2 = "20.6text";
        $var1 += $var2;
        print ($var1);
    ?>
    1. 10
    2. 30.6
    3. 31
    4. 30
    5. None of the above

  45. Which constant is used in the mysql_fetch_array(...) function?
    1. MYSQL_ASSOC?
    2. MYSQL_BOTH?
    3. MYSQL_NUM?
    4. All of the above
    5. None of the above

  46. 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");
    ?>
    1. one: 4
      two: 5
      three: 5
    2. one: 4
      two: 4
      three: 4
    3. one: 5
      two: 5
      three: 5
    4. one: 4
      two: 5
      three: 4
    5. None of the above

  47. $returnCode = mysql_errno();
    1. Does nothing if MySQL has not encountered an error.
    2. Sets variable $returnCode to an integer representing the number of errors in the last database accessed.
    3. Sets variable $returnCode to a string value containing an error number from MySQL.
    4. Sets variable $returnCode to an integer representing the error number of the previous MySQL function call.
    5. None of the above

  48. In an argument which one of the below lines of code will fetch one argument at a time.
    1. func_num_args
    2. func_get_args
    3. func_get_one
    4. func_get_arg
    5. None of the above

  49. The operator >> means:
    1. MUCH greater than
    2. Tab twice to the right
    3. Shift all bits to the right
    4. Important Comment!
    5. None of the above

  50. 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");
    ?>
    1. a 12 row table
    2. which browser someone is using to surf your page
    3. an empty grid with rows and columns
    4. a multiplication table
    5. None of the above

  51. A session is only valid on a single server.
    1. True
    2. False
    3. Don't know.
    4. Statement is incorrect.
    5. None of the above

  52. What is a reason for an internet server provider (ISP) to support PHP?
    1. There's less risk to the server with PHP applications than with CGIs.
    2. Microsoft provides excellent support for PHP.
    3. PHP is very similar to Visual Basic and so is very easy to use.
    4. All of the above
    5. None of the above