wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

ElevB_Ch4_Exercise

Total questions: 23

Worksheet time: 12mins

Name
Class
Date
1.

In the context of web applications, what primary role does a database server perform?

a)

Handles user input via HTTP requests.

b)

Executes client-side data validation.

c)

Stores information such as usernames and passwords.

d)

Renders the final HTML file to the client browser.

2.

A web server relies on an Application Programming Interface (API) to communicate with a database. What can a web server use this API for?

a)

Converting SQL syntax into PHP code.

b)

Managing the server's operating system resources.

c)

Retrieving, inserting, updating, or deleting records in a database.

d)

Encrypting client passwords before transmission.

3.

Which mysqli API function is specifically used to establish a connection between the database and the web server?

a)

mysqli_num_rows()

b)

mysqli_connect()

c)

mysqli_fetch_assoc()

d)

mysqli_query()

4.

What is the function of mysqli_query()?

a)

Sanitize user-provided values.

b)

Fetch the next row from the query result.

c)

Establish a connection to the database.

d)

Execute an SQL query on the connected database.

5.

What is the purpose of the mysqli_fetch_assoc() function?

a)

Execute a specific SQL query.

b)

Return the number of rows in the result.

c)

Close the database connection.

d)

Fetch the next row in the query result as an associative array.

6.

How many parameters are required by the mysqli_connect() function to establish a database connection?

a)

Five

b)

Four

c)

Three

d)

Two

7.

In the parameters required by mysqli_connect(), what is the third parameter (in order from left to right)?

a)

Name of the database

b)

Hostname

c)

Username

d)

Password

8.

What attack method exploits server-script using user-provided values without any precautions in an SQL query?

a)

Cross-Site Scripting (XSS)

b)

Denial of Service (DoS)

c)

Man-in-the-Middle (MITM)

d)

SQL Injection

9.

What does sanitizing a value mean in the context of preventing SQL injection?

a)

Encrypting the connection link

b)

Converting the value to a Boolean

c)

Escaping certain special characters in the string

d)

Hashing the value for secure storage

10.

Which mysqli function is specifically used to receive a query result object as a parameter and returns the number of rows in that query result?

a)

mysqli_connect()

b)

mysqli_query()

c)

mysqli_num_rows()

d)

mysqli_fetch_assoc()

11.

In the typical setup using mysqli_connect(), what is the recommended practice for storing credentials like hostname, username, and password?

a)

Encrypting the credentials before passing them into the function.

b)

Storing credentials in a global array that is accessed by the function.

c)

Storing credentials in variables and passing the variables into the function call.

d)

Passing strings directly into the function call.

12.

When mysqli_connect() is invoked, what is the return value if the connection establishment fails?

a)

An error string.

b)

A Boolean value of False.

c)

A mysqli object.

d)

A Boolean value of True.

13.

Which of the following is considered a database-side reason for a failed connection attempt?

a)

The server's firewall blocked communication to the database server.

b)

The database server is offline.

c)

Incorrect credentials (username/password) provided.

d)

Incorrect API is used to connect to the database.

14.

If the web server successfully connects to the database, the mysqli_connect() function returns a mysqli object. What is this object analogized to for subsequent query executions?

a)

A database table object.

b)

A ticket issued by the database.

c)

A SQL query string.

d)

A security certificate.

15.

If mysqli_query() attempts to execute a SELECT query and the execution fails, what value does the function return?

a)

A mysqli_result object.

b)

A Boolean True.

c)

A Boolean False.

d)

An integer 0.

16.

To retrieve data using a SELECT statement in PHP, the query result object must be iterated through. What two programming constructs are typically used together for this iteration?

a)

A for loop and mysqli_query()

b)

A do-while loop and mysqli_num_rows()

c)

A while loop and mysqli_fetch_assoc()

d)

A foreach loop and mysqli_connect()

17.

When forming an SQL query from a client-sent string in PHP, how should the filter parameter be enclosed to meet the critical syntactical requirement?

a)

Double-quotes around the parameter

b)

Backticks around the parameter

c)

Single-quotes around the parameter

d)

Escape the parameter with a backslash

18.

In the SQL injection example using a double dash (--) at the end of the payload, what is the resulting effect on the executed SQL statement?

a)

It causes a syntax error and stops execution

b)

It forces the database to return an empty set

c)

It prevents the string from being sanitized

d)

It turns the rest of the SQL into a comment

19.

Which statement best describes the behavior of die() when handling failed connection attempts with an error message?

a)

Terminates the script and outputs the string

b)

Attempts reconnection and logs a warning

c)

Terminates connection but suppresses the error

d)

Outputs the string and continues execution

20.

To format an SQL IN clause for text values like ('value1', 'value2'), which separator must be given to implode()?

a)

"" (empty string)

b)

', ' (comma and space)

c)

", ' (double quote, comma, single quote)

d)

"', '" (single quote, comma, single quote)

21.

Why is enclosing user input in single-quotes important when constructing SQL filters?

a)

It automatically escapes special characters

b)

It disables indexing on the column

c)

It treats values as string literals

d)

It converts text to numeric types

22.

If mysqli_connect() omits the port parameter on a server using a non-default port, what likely occurs?

a)

MySQL redirects to the correct port

b)

Connection fails due to wrong port

c)

PHP auto-detects the custom port

d)

Connection succeeds using default port

23.

In a script using die("ERROR: Webserver could not connect to database!"), what immediate outcome should you expect?

a)

Execution stops after printing the message

b)

The database reconnects then proceeds

c)

The script continues but logs the error

d)

The page loads with a warning banner