Quiz 9 & 10 Flashcards
T/F - JSON objects are wrapped in square brackets []
False
They’re wrapped in curly braces
T/F - in PHP the try block represents block of code in which exception can arise.
True
T/F - The error_reporting setting specifies whether error messages should or should not be displayed in the browser.
False. That is the display_error setting.
The error_reporting setting specifies which type of errors are to be reported
In php, any files that are sent to the server (via a web form) are held in the ______ array.
$_FILES
T/F - The json_decode() function is used to convert a JSON encoded string into a PHP datatype
True
In the following code, what is the purpose of the isset function?
if (isset($_POST[‘name’]) && empty(trim($_POST[‘name’])))
{
echo “<p class="alert">Form is missing data<p>”; $form_complete=false;
}
To determine whether the name element has been retrieved
Isset checks whether a variable is set (declared & not null) and returns a boolean value
What is the main advantage of sessions over cookies?
Data is stored on the server for sessions
T/F - The $_FILES variable is an associative array like $_GET and $_POST
True
T/F - JSON keys are always numbers, while JSON values can be a string, number, Boolean, null, object, or an array
False
Keys are always strings
Values can be anything
T/F - When an HTML form uses method=”get” and submits to a PHP script, $_GET will contain all the values entered in the form.
True
What method sends input to a PHP script via the URL?
GET
PHP - Which statement would correctly function to create an associative array?
A $age=array(Bob => 5, Jim=> 7, Ted=> 12);
B $age=array(‘Bob’ => 5; ‘Jim’=> 7; ‘Ted’=> 12);
C $age=array(‘Bob’ => 5, ‘Jim’=> 7, ‘Ted’=> 12);
D $age=array(‘Bob’ = 5, ‘Jim’= 7, ‘Ted’ = 12)
C
PAY ATTENTION TO THE COMMAS, SINGLE QUOTES AROUND NAMES, ARROWS
What is the value displayed when the following is executed? Assume that the code was executed using the following URL:
testscript.php?c=25
<?php
function process($c, $d = 25)
{
global $e;
$retval = $c + $d - $_GET[‘c’] - $e;
return $retval;
}
$e = 10;
echo process(5);
?
-5.
For a MySQL procedural connection, what is required?
$conn = ______________($__________, $________, $________);
$conn = mysqli_connect($servername, $username, $password);
4 Variables needed are: servername, database, username, password
The query() method of a MySQLi object will return a _________________ object.
mysqli_result