6 quizzes found.

Consider the following code snippet; What would go in place of the ???? above for this script to function properly?

<?php$link = mysqli_connect("hostname", "username", "password");if(!$link){ $error = ?????? die("Could not connect to the database: $error");}?>
  1. mysqli_connect_error();
  2. mysqli_connect_error($link);
  3. mysqli_error();
  4. $_MySQL['connect_error']
  5. mysqli_get_connect_error();

Choose 2 answers

Consider the following code snippet; Assuming this snippet is a smaller part of a correctly written script, what actions must occur in place of the ????? in the above code snippet to insert a row with the following values: 10, 20.2, foo, string?

<?php$query = "INSERT INTO mytable (myinteger, mydouble, myblob, myvarchar) VALUES (?, ?, ?, ?)";$statement = mysqli_prepare($link, $query);if(!$statement){ die(mysqli_error($link));}/* The variables being bound to by MySQLi don't need to exist prior to binding */mysqli_bind_param($statement, "idbs", $myinteger, $mydouble, $myblob, $myvarchar);/* ???????????? */ /* execute the query, using the variables as defined. */if(!mysqli_execute($statement)){ die(mysqli_error($link));}?>
  1. A transaction must be begun and the variables must be assigned
  2. Each value must be assigned prior to calling mysqli_bind_param(), and thus nothing should be done
  3. Use mysqli_bind_value() to assign each of the values
  4. Assign $myinteger, $mydouble, $myblob, $myvarchar the proper values

Choose 1 answers

Consider the following code snippet; Assuming this code snippet is part of a larger correct application, what must be done in place of the ???? above for the correct output to be displayed?

<?php$query = "SELECT first, last, phone FROM contacts WHERE first LIKE 'John%'";$statement = mysqli_prepare($link, $query);mysqli_execute($statement);/* ???? */while(($result = mysqli_stmt_fetch($statement))){ print "Name: $first $last\n"; print "Phone: $phone\n\n";}?>
  1. None of the above
  2. mysqli_fetch_columns($first, $last, $phone);
  3. mysqli_stmt_bind_result($statement, $first, $last, $phone);
  4. A while loop, fetching the row and assigning $first, $last, and $phone the proper value

Choose 1 answers

Which of the following cases are cases when you should use transactions?

  1. Updating a single row in a table
  2. Inserting a new row into a single table
  3. Performing a stored procedure
  4. Selecting rows from multiple different tables
  5. Updating a single row in multiple different tables

Choose 1 answers

When writing portable database code using PDO, what is the PDO::ATTR_CASE attribute useful for?

  1. None of the above
  2. Ensuring that all columns are of a particular case when fetched
  3. Adjusting the case of a query before it is processed for compatibility reasons
  4. Controls the switch logic of how queries are processed
  5. Allows you to adjust the memory cache (or "case") for increased performance

Choose 1 answers