Don't forget to hit the ⭐ if you like this repo.
Please answer the following 50 multiple-choice questions to test your knowledge in MySQL and CRUD. You must place your answer file in the submission folder. Within the submission/Q5/set_a
folder, create a folder called your github_id
.
-
Which of the following is a popular open-source relational database management system?
- a) MySQL
- b) MongoDB
- c) Oracle
- d) SQLite
-
How do you establish a connection to a MySQL database in PHP?
- a)
mysqli_connect()
- b)
mysql_connect()
- c)
pdo_connect()
- d)
db_connect()
- a)
-
Which PHP function is used to execute an SQL query?
- a)
mysql_query()
- b)
mysqli_query()
- c)
pdo_query()
- d)
db_query()
- a)
-
What does SQL stand for?
- a) Structured Query Language
- b) Sequential Query Language
- c) Specific Query Language
- d) Structured Question Language
-
How do you fetch a single row of data from a MySQL query result in PHP?
- a)
mysqli_fetch_row()
- b)
mysqli_fetch_array()
- c)
mysqli_fetch_assoc()
- d)
mysqli_fetch_object()
- a)
-
Which PHP function is used to retrieve the number of rows returned by a MySQL query?
- a)
mysql_num_rows()
- b)
mysqli_num_rows()
- c)
pdo_num_rows()
- d)
db_num_rows()
- a)
-
How do you escape special characters in a string before inserting it into a MySQL database?
- a)
mysql_escape_string()
- b)
mysqli_escape_string()
- c)
pdo_escape_string()
- d)
db_escape_string()
- a)
-
Which SQL statement is used to insert data into a MySQL database?
- a)
INSERT INTO
- b)
UPDATE
- c)
SELECT
- d)
DELETE FROM
- a)
-
How do you retrieve the ID of the last inserted row in a MySQL database using PHP?
- a)
mysql_insert_id()
- b)
mysqli_insert_id()
- c)
pdo_insert_id()
- d)
db_insert_id()
- a)
-
What is the result of the following PHP code?
$conn = mysqli_connect("localhost", "username", "password", "database"); if (!$conn) { die("Connection failed: " . mysqli_connect_error()); }
- a) Establishes a connection to the MySQL database
- b) Prints "Connection failed" if the connection is unsuccessful
- c) Terminates the script execution if the connection fails
- d) All of the above
-
Which PHP function is used to close a connection to a MySQL database?
- a)
mysql_close()
- b)
mysqli_close()
- c)
pdo_close()
- d)
db_close()
- a)
-
What does the
mysqli_fetch_array()
function return in PHP?- a) An associative array
- b) A numeric array
- c) Both associative and numeric arrays
- d) A single value
-
How do you execute a prepared statement with placeholders in PHP using MySQLi?
- a)
mysqli_prepare()
- b)
mysqli_execute()
- c)
mysqli_bind_param()
- d)
mysqli_stmt_execute()
- a)
-
Which PHP function is used to handle errors during MySQL database operations?
- a)
mysql_error()
- b)
mysqli_error()
- c)
pdo_error()
- d)
db_error()
- a)
-
How do you retrieve the number of affected rows after an
UPDATE
orDELETE
query in MySQLi?- a)
$mysqli->affected_rows
- b)
mysqli_affected_rows()
- c)
$pdo->affected_rows
- d)
db_affected_rows()
- a)
-
Which PHP function is used to handle transactions in MySQL databases?
- a)
mysql_transaction()
- b)
mysqli_transaction()
- c)
pdo_transaction()
- d)
db_transaction()
- a)
-
How do you retrieve the auto-incremented ID of the last inserted row in PDO?
- a)
$pdo->lastInsertId()
- b)
pdo_last_insert_id()
- c)
$pdo->insertId()
- d)
pdo_insert_id()
- a)
-
Which SQL statement is used to update data in a MySQL database?
- a)
UPDATE
- b)
INSERT INTO
- c)
SELECT
- d)
DELETE FROM
- a)
-
How do you prevent SQL injection in PHP when working with MySQL databases?
- a) Sanitize user input using filter functions
- b) Use prepared statements with placeholders
- c) Escape special characters in SQL queries
- d) All of the above
-
What does the SQL statement
SELECT * FROM users WHERE age > 25
do?- a) Retrieves all users with an age greater than 25
- b) Retrieves all users with an age less than 25
- c) Retrieves all users from the "age" table
- d) Retrieves all columns from the "users" table
-
How do you retrieve the number of rows returned by a PDO query?
- a)
$pdo->rowCount()
- b)
pdo_num_rows()
- c)
count($pdo)
- d)
count($pdo->fetchAll())
- a)
-
What is the result of the following code?
$sql = "SELECT * FROM users"; $result = mysqli_query($conn, $sql); $count = mysqli_num_rows($result); echo $count;
- a) Prints the number of rows in the "users" table
- b) Prints the number of columns in the "users" table
- c) Prints the result of the query
- d) Error
-
Which PHP function is used to fetch the next row from a MySQL query result?
- a)
mysql_fetch_row()
- b)
mysqli_fetch_row()
- c)
pdo_fetch_row()
- d)
db_fetch_row()
- a)
-
How do you retrieve the value of a specific column from a MySQL query result in PHP?
- a) By specifying the column name in the fetch function
- b) By accessing the column index in the fetch function
- c) By using the
mysql_result()
function - d) By using the
mysqli_result()
function
-
Which PHP function is used to free the memory associated with a MySQL query result?
- a)
mysql_free_result()
- b)
mysqli_free_result()
- c)
pdo_free_result()
- d)
db_free_result()
- a)
-
How do you retrieve the number of fields (columns) in a MySQL query result in PHP?
- a)
$result->num_fields()
- b)
mysqli_num_fields($result)
- c)
$result->field_count()
- d)
count($result)
- a)
-
Which SQL statement is used to delete data from a MySQL database?
- a)
DELETE FROM
- b)
UPDATE
- c)
INSERT INTO
- d)
SELECT
- a)
-
How do you retrieve the value of a specific field (column) from a MySQL query result in PHP?
- a) By specifying the field name in the fetch function
- b) By accessing the field index in the fetch function
- c) By using the
mysql_field_result()
function - d) By using the
mysqli_field_result()
function
-
What is the result of the following code?
$sql = "SELECT COUNT(*) FROM users"; $result = mysqli_query($conn, $sql); $count = mysqli_fetch_array($result)[0]; echo $count;
- a) Prints the number of rows in the "users" table
- b) Prints the number of columns in the "users" table
- c) Prints the result of the query
- d) Error
-
How do you retrieve the error message from a failed MySQL query in PHP?
- a)
$conn->error
- b)
mysqli_error()
- c)
$pdo->error
- d)
db_error()
- a)
-
Which PHP function is used to fetch all rows from a MySQL query result at once?
- a)
mysql_fetch_all()
- b)
mysqli_fetch_all()
- c)
pdo_fetch_all()
- d)
db_fetch_all()
- a)
-
How do you retrieve the current auto-increment value for a table in MySQL using PHP?
- a)
SHOW AUTO_INCREMENT FROM table
- b)
SELECT AUTO_INCREMENT FROM table
- c)
AUTO_INCREMENT()
- d)
mysql_auto_increment()
- a)
-
Which PHP function is used to escape special characters in a string before inserting it into a MySQL database?
- a)
mysql_escape_string()
- b)
mysqli_escape_string()
- c)
pdo_escape_string()
- d)
db_escape_string()
- a)
-
How do you retrieve the number of affected rows after an
INSERT
query in MySQLi?- a)
$mysqli->affected_rows
- b)
mysqli_affected_rows()
- c)
$pdo->affected_rows
- d)
db_affected_rows()
- a)
-
What is the result of the following code?
$sql = "SELECT * FROM users WHERE id = '1'"; $result = mysqli_query($conn, $sql); $row = mysqli_fetch_assoc($result); echo $row['name'];
- a) Prints the name of the user with ID 1
- b) Prints the name of the first user in the table
- c) Prints the ID of the user with name '1'
- d) Error
-
How do you retrieve the number of rows affected by an
UPDATE
orDELETE
query in PDO?- a)
$pdo->rowCount()
- b)
pdo_num_rows()
- c)
count($pdo)
- d)
count($pdo->fetchAll())
- a)
-
Which PHP function is used to handle transactions in PDO?
- a)
$pdo->transaction()
- b)
pdo_transaction()
- c)
$pdo->beginTransaction()
- d)
pdo_begin_transaction()
- a)
-
How do you retrieve the auto-incremented ID of the last inserted row in MySQLi?
- a)
$mysqli->insert_id
- b)
mysqli_insert_id()
- c)
$mysqli->lastInsertId()
- d)
mysqli_last_insert_id()
- a)
-
What is the result of the following code?
$sql = "INSERT INTO users (name, email) VALUES ('John Doe', '[email protected]')"; $result = mysqli_query($conn, $sql); if ($result === true) { echo "User inserted successfully."; } else { echo "Error inserting user."; }
- a) Prints "User inserted successfully" if the query is successful
- b) Prints "Error inserting user" if the query fails
- c) Prints nothing
- d) Error
-
How do you retrieve the number of fields (columns) in a MySQL query result in PDO?
- a)
$result->columnCount()
- b)
pdo_num_fields()
- c)
count($result)
- d)
count($result->fetch())
- a)
-
Which PHP function is used to fetch the next row from a MySQL query result in PDO?
- a)
$result->nextRow()
- b)
pdo_fetch_row()
- c)
$result->fetch()
- d)
pdo_next_row()
- a)
-
What is the result of the following code?
$sql = "SELECT * FROM users"; $result = mysqli_query($conn, $sql); $count = mysqli_num_fields($result); echo $count;
- a) Prints the number of fields (columns) in the "users" table
- b) Prints the number of rows in the "users" table
- c) Prints the result of the query
- d) Error
-
How do you retrieve the value of a specific column from a MySQL query result in PDO?
- a) By specifying the column name in the fetch function
- b) By accessing the column index in the fetch function
- c) By using the
pdo_result()
function - d) By using the
pdo_fetch_column()
function
-
Which PHP function is used to free the memory associated with a MySQL query result in PDO?
- a)
$result->free()
- b)
pdo_free_result()
- c)
$result->close()
- d)
pdo_free_memory()
- a)
-
How do you retrieve the number of rows returned by a MySQL query in PDO?
- a)
$result->rowCount()
- b)
pdo_num_rows()
- c)
count($result)
- d)
count($result->fetch())
- a)
-
What is the result of the following code?
$sql = "SELECT * FROM users WHERE age > 25"; $result = mysqli_query($conn, $sql); $count = mysqli_num_rows($result); echo $count;
- a) Prints the number of users with an age greater than 25
- b) Prints the number of users with an age less than 25
- c) Prints the result of the query
- d) Error
-
How do you retrieve the error message from a failed MySQL query in PDO?
- a)
$pdo->errorInfo()
- b)
pdo_error()
- c)
$pdo->errorMessage()
- d)
pdo_error_message()
- a)
-
Which PHP function is used to fetch all rows from a MySQL query result at once in PDO?
- a)
$result->fetchAll()
- b)
pdo_fetch_all()
- c)
$result->getAll()
- d)
pdo_get_all()
- a)
-
How do you retrieve the current auto-increment value for a table in MySQL using PHP and MySQLi?
- a)
SHOW AUTO_INCREMENT FROM table
- b)
SELECT AUTO_INCREMENT FROM table
- c)
AUTO_INCREMENT()
- d)
mysqli_auto_increment()
- a)
-
What is the result of the following code?
$sql = "DELETE FROM users WHERE id = 1"; $result = mysqli_query($conn, $sql); if ($result) { echo "User deleted successfully."; } else { echo "Error deleting user."; }
- a) Prints "User deleted successfully" if the query is successful
- b) Prints "Error deleting user" if the query fails
- c) Prints nothing
- d) Error
Please create an Issue for any improvements, suggestions or errors in the content.
You can also contact me using Linkedin for any other queries or feedback.