NEW
Font size
WorksheetsElevB_Ch4_Exercise
Total questions: 23
Worksheet time: 12mins
In the context of web applications, what primary role does a database server perform?
Handles user input via HTTP requests.
Executes client-side data validation.
Stores information such as usernames and passwords.
Renders the final HTML file to the client browser.
A web server relies on an Application Programming Interface (API) to communicate with a database. What can a web server use this API for?
Converting SQL syntax into PHP code.
Managing the server's operating system resources.
Retrieving, inserting, updating, or deleting records in a database.
Encrypting client passwords before transmission.
Which mysqli API function is specifically used to establish a connection between the database and the web server?
mysqli_num_rows()
mysqli_connect()
mysqli_fetch_assoc()
mysqli_query()
What is the function of mysqli_query()?
Sanitize user-provided values.
Fetch the next row from the query result.
Establish a connection to the database.
Execute an SQL query on the connected database.
What is the purpose of the mysqli_fetch_assoc() function?
Execute a specific SQL query.
Return the number of rows in the result.
Close the database connection.
Fetch the next row in the query result as an associative array.
How many parameters are required by the mysqli_connect() function to establish a database connection?
Five
Four
Three
Two
In the parameters required by mysqli_connect(), what is the third parameter (in order from left to right)?
Name of the database
Hostname
Username
Password
What attack method exploits server-script using user-provided values without any precautions in an SQL query?
Cross-Site Scripting (XSS)
Denial of Service (DoS)
Man-in-the-Middle (MITM)
SQL Injection
What does sanitizing a value mean in the context of preventing SQL injection?
Encrypting the connection link
Converting the value to a Boolean
Escaping certain special characters in the string
Hashing the value for secure storage
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?
mysqli_connect()
mysqli_query()
mysqli_num_rows()
mysqli_fetch_assoc()
In the typical setup using mysqli_connect(), what is the recommended practice for storing credentials like hostname, username, and password?
Encrypting the credentials before passing them into the function.
Storing credentials in a global array that is accessed by the function.
Storing credentials in variables and passing the variables into the function call.
Passing strings directly into the function call.
When mysqli_connect() is invoked, what is the return value if the connection establishment fails?
An error string.
A Boolean value of False.
A mysqli object.
A Boolean value of True.
Which of the following is considered a database-side reason for a failed connection attempt?
The server's firewall blocked communication to the database server.
The database server is offline.
Incorrect credentials (username/password) provided.
Incorrect API is used to connect to the database.
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 database table object.
A ticket issued by the database.
A SQL query string.
A security certificate.
If mysqli_query() attempts to execute a SELECT query and the execution fails, what value does the function return?
A mysqli_result object.
A Boolean True.
A Boolean False.
An integer 0.
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 for loop and mysqli_query()
A do-while loop and mysqli_num_rows()
A while loop and mysqli_fetch_assoc()
A foreach loop and mysqli_connect()
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?
Double-quotes around the parameter
Backticks around the parameter
Single-quotes around the parameter
Escape the parameter with a backslash
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?
It causes a syntax error and stops execution
It forces the database to return an empty set
It prevents the string from being sanitized
It turns the rest of the SQL into a comment
Which statement best describes the behavior of die() when handling failed connection attempts with an error message?
Terminates the script and outputs the string
Attempts reconnection and logs a warning
Terminates connection but suppresses the error
Outputs the string and continues execution
To format an SQL IN clause for text values like ('value1', 'value2'), which separator must be given to implode()?
"" (empty string)
', ' (comma and space)
", ' (double quote, comma, single quote)
"', '" (single quote, comma, single quote)
Why is enclosing user input in single-quotes important when constructing SQL filters?
It automatically escapes special characters
It disables indexing on the column
It treats values as string literals
It converts text to numeric types
If mysqli_connect() omits the port parameter on a server using a non-default port, what likely occurs?
MySQL redirects to the correct port
Connection fails due to wrong port
PHP auto-detects the custom port
Connection succeeds using default port
In a script using die("ERROR: Webserver could not connect to database!"), what immediate outcome should you expect?
Execution stops after printing the message
The database reconnects then proceeds
The script continues but logs the error
The page loads with a warning banner
