Lab 3 Self Assessment

Lab3 Self Assessment

Question 1 

Match the following SQLi functions to their correct function definition

Question 1 options:

mysqli_connect()

mysqli_query()

mysqli_fetch_row()

mysqli_num_rows()


Solution

Answer

mysqli_connect()            :   Opens a new connection to the MySQL server
mysqli_query()                 :  Performs a query against a database.
mysqli_fetch_row()    :      fetches one row from a result-set and returns it as an enumerated array
mysqli_num_rows()             : returns the number of rows in a result set.




Question 2 (1 point)

 

The SQLi function mysqli_query( ) performs a query against a database.  What are the 2 compulsory parameter values that must be passed into this function call?

Question 2 options:




Answer


MySQL connection & SQL query string





Question 3 (1 point)

 

What is the purpose of the SQLi function mysql_num_rows() ?

Question 3 options:


Answer: Q3


Returns the number of rows in a result set



Question 4 (1 point)

 
Question 4 options:

In the following php codes, state the line number that executes the command to insert data?

Code



answer Q4


line 4




Question 5 (1 point)

 
Question 5 options:

In the following php codes, state the line number which executes the command to update data?

update



Answer Q5


line 5




Question 6 (1 point)

 

For the following PHP scripts, what are the answers for the missing function calls, in the correct order?

 

<?php

$con = _____[A1]___________ ("localhost","my_user","my_password","my_db");

if (mysqli_connect_errno()) {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  exit();
}
$sql = "SELECT Lastname, Age FROM Persons ORDER BY Lastname";

if ($result = _____[A2]_________ ($con, $sql)) {


  // Fetch one and one row
  while ($row = mysqli_fetch_row($result)) {
    printf ("%s (%s)\n", $row[0], $row[1]);
  }

  mysqli_free_result($result);

}
___[A3]_________($con);

?>

Question 6 options:



Answer Q6

A1: mysqli_connect, A2: mysqli_query,  A3: mysqli_close



Comments

Popular posts from this blog

Simple Login Example (PHP Server + Android Client)

Lab 6: Using split