Web Data Management Chapters 4-6

40 Questions

Settings
Please wait...
Data Management Quizzes & Trivia

Web data management chapters 4-6


Questions and Answers
  • 1. 
    To create a PDO object, you code the _____________________ keyword, followed by PDO, followed by the three arguments that it requires.  
  • 2. 
    To execute a SELECT statement, you use the _____________________ method of the PDO object that connects to the database.
  • 3. 
    To execute an INSERT statement, you use the _____________________ method of the PDO object that connects to the database.
  • 4. 
    To handle the PDO exceptions that can occur when database methods are executed, you use a _____________________ statement.
  • 5. 
    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.
  • 6. 
    To return an array for the first row of a result set that’s returned by a SELECT statement, you use the fetch method of the _____________________________ object that represents the result set.
  • 7. 
    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.
  • 8. 
    What date did you complete this worksheet _____________________________ .
  • 9. 
    When you create a PDO object, you have to pass all but one of these arguments to it: Which one is it?  
    • A. 

      Data source name

    • B. 

      Server name

    • C. 

      User name

    • D. 

      Password

  • 10. 
    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 
    • A. 

      PDO object

    • B. 

      PDOStatement object

    • C. 

      PDOException object

    • D. 

      Result set array

  • 11. 
    Which of the following is the correct way to code a PHP statement that returns the result set for a SELECT statement that’s stored in $statement if the PDO object is $db?  
    • A. 

      $results = $db->query($statement);

    • B. 

      $results = $db->exec($statement);

    • C. 

      $results = query->$db($statement);

    • D. 

      $results = exec->$db($statement);

  • 12. 
    Which of the following is the correct way to code a PHP statement that puts the first row of PDOStatement object named $products in an array named $product?  
    • A. 

      $product = $db->query($products);

    • B. 

      $product = $db->fetch($products);

    • C. 

      $product = $products->query();

    • D. 

      $product = $products->fetch();

  • 13. 
    • A. 

      Create a PDOStatement object named $db that connects to the right database

    • B. 

      Create a PDOStatement object named $db-> that connects to the right database

    • C. 

      Create a PDO object named $db that connects to the right database

    • D. 

      Create a PDO object named $db-> that connects to the right database

  • 14. 
    Code example 4-1 The starting code for the index.php file which is the first page of an application <?php     require 'database.php';     $category_id = $_GET['category_id'];     if (!isset($category_id)) {         $category_id = 1;     }       // Routine 1     $query = "SELECT * FROM categories               WHERE categoryID = $category_id";     $category = $db->query($query);     $category = $category->fetch();     $category_name = $category['categoryName'];       // Routine 2     $query = "SELECT * FROM products               WHERE categoryID = $category_id               ORDER BY productID";     $products = $db->query($query); ?> (Refer to code example 4-1) What does routine 1 store in the variable named $category_name?  
    • A. 

      The category name for the first row in the categories table of the database

    • B. 

      The category name for the row in categories table that corresponds to the value in $category_id

    • C. 

      The category name for the row in categories table that has a category ID of 1

    • D. 

      An array of the category names in the categories table

  • 15. 
      Code example 4-1 The starting code for the index.php file which is the first page of an application (Refer to code example 4-1) What does routine 2 store in the variable named $products?
    • A. 

      A PDOStatement object for all rows in the products table

    • B. 

      A PDOStatement object for the columns in the first row in the products table

    • C. 

      A PDOStatement object for the rows in the products table that have a category ID equal to the value in $category_id

    • D. 

      A PDOStatement object for the rows in the products table that have a category ID equal to 1

  • 16. 
    When you use the MVC pattern, the model consists of the PHP files that work with and represent the _________________________ of the application.  
  • 17. 
    When you use the MVC pattern, the ___________________ consists of the PHP files that make up the user interface of the application.
  • 18. 
    When you code a function in PHP, you start with the keyword __________________.  
  • 19. 
    When you code a function in PHP, you can list one or more ____________________ that must be passed to the function.
  • 20. 
    To call a function in PHP, you code the function name followed by a list of any _________________________ that are required.
  • 21. 
    To pass data back to the statement that calls a function, the function can use the _________________________ statement.  
  • 22. 
    To make a variable that’s declared outside a function available to the function, you must code the _________________________ keyword.
  • 23. 
    When you _______________________ an HTTP request, all processing takes place on the server before the response is returned to the browser.
  • 24. 
    When you use the MVC pattern, the controller gets the HTTP requests and then directs the use of the files that represent  
    • A. 

      The model, the view, and the database

    • B. 

      The database and the view

    • C. 

      The model, the view, and the user interface

    • D. 

      The model and the view

  • 25. 
    When you use the MVC pattern, you   
    • A. 

      Make each layer as independent as possible

    • B. 

      Perform all data validation on the client

    • C. 

      Use the pattern for every page in the application

    • D. 

      Put all of the PHP code in the controller

  • 26. 
    • A. 

      It’s easier to make changes to the application

    • B. 

      Web designers can work independently on the view

    • C. 

      There’s less repetition of code

    • D. 

      It’s easier to test and debug the application

    • E. 

      The application runs more efficiently

  • 27. 
    Code example 5-1   function get_product($product_id) {     global $db;     $query = "SELECT * FROM products               WHERE productID = '$product_id'";     $product = $db->query($query);     $product = $product->fetch();     return $product; } (Refer to code example 5-1) What does this function return when it is called?
    • A. 

      An array of all the rows in the products table

    • B. 

      An array of all the rows with the specified category ID

    • C. 

      An array of the columns in the first row of the products table

    • D. 

      An array of the columns in the row with the specified product ID

  • 28. 
    Code example 5-1   function get_product($product_id) {     global $db;     $query = "SELECT * FROM products               WHERE productID = '$product_id'";     $product = $db->query($query);     $product = $product->fetch();     return $product; } (Refer to code example 5-1) Which of the following is a proper PHP statement for calling the function in this example and storing the returned result in a variable named $product.  
    • A. 

      $product = get_product($product_id);

    • B. 

      $product = get_product(product_id);

    • C. 

      $product = $get_product($product_id);

    • D. 

      $product = $get_product(product_id);

  • 29. 
    When you use the header function to redirect a request,
    • A. 

      A response is sent to the web server so it requests another page

    • B. 

      The web server returns a new page to the browser

    • C. 

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

    • D. 

      The web server returns a new page to the controller of the MVC pattern

  • 30. 
    One reason for using the header function to redirect a request
    • A. 

      Is that it’s more efficient than forwarding a request

    • B. 

      Is to have a PHP file run itself again

    • C. 

      Is to reduce the number of round trips that are required

    • D. 

      Is to do all processing for the request on the server

  • 31. 
    As you ____________________ an application, you try to make it fail.
  • 32. 
    When you test an application, you start by using ____________________ data.
  • 33. 
    A __________________ error violates the rules for how PHP statements must be written.
  • 34. 
    A simple way to trace the execution of an application is to insert __________________ statements at appropriate points within the code.
  • 35. 
    When a breakpoint is reached while you’re testing an application with NetBeans, you can view the values of the available __________________.
  • 36. 
    When you’re using NetBeans, you can step through the execution of an application one statement at a time by clicking on the Step __________________ button.
  • 37. 
    The goal of testing is to
    • A. 

      Fix all errors in the application

    • B. 

      Find all errors in the application

    • C. 

      Make sure the application works with valid data

    • D. 

      Make sure the application works with invalid data

  • 38. 
    An error that lets the application run but produces the wrong results is known as a
    • A. 

      Runtime error

    • B. 

      User error

    • C. 

      Logic error

    • D. 

      Syntax error

  • 39. 
    An error that occurs after an application is running is known as a
    • A. 

      Runtime error

    • B. 

      User error

    • C. 

      Logic error

    • D. 

      Syntax error

  • 40. 
    When you click on the Continue button while you’re debugging with NetBeans, the application
    • A. 

      Runs to the next breakpoint

    • B. 

      Executes the next statement in sequence

    • C. 

      Lets you step through the statements

    • D. 

      Removes the breakpoint