Which SQL statement is used to retrieve data from a table?
A
FETCH B
SELECT C
GET D
RETRIEVE
Analysis & Theory
The correct SQL statement to retrieve data is `SELECT`.
Which PHP function is commonly used to execute a SELECT query?
A
mysqli_connect() B
mysqli_query() C
mysqli_fetch() D
mysqli_insert()
Analysis & Theory
`mysqli_query()` is used to execute SQL queries like SELECT.
Which function retrieves rows from a SELECT result as an associative array?
A
mysqli_fetch_array() B
mysqli_fetch_assoc() C
mysqli_num_rows() D
mysqli_get()
Analysis & Theory
`mysqli_fetch_assoc()` fetches a result row as an associative array.
What does this SQL statement do?
```
SELECT * FROM users;
```
A
Selects all columns and rows from the users table B
Deletes the users table C
Selects only one column D
Creates a table
Analysis & Theory
It selects all columns and rows from the `users` table.
Which SQL statement is used to delete records from a table?
A
REMOVE FROM B
DELETE FROM C
DROP D
CUT FROM
Analysis & Theory
The `DELETE FROM` statement is used to remove rows from a table.
What does this SQL statement do?
```
DELETE FROM users WHERE id = 5;
```
A
Deletes the entire users table B
Deletes the user with id 5 C
Selects the user with id 5 D
Updates the user with id 5
Analysis & Theory
It deletes the row where the id equals 5 in the users table.
What happens if you run `DELETE FROM users;` without a WHERE clause?
A
Deletes one row B
Deletes all rows in the users table C
Throws an error D
Selects all rows
Analysis & Theory
Without a WHERE clause, DELETE removes all rows from the table.
Which function is used to count the number of rows returned by a SELECT query?
A
mysqli_count() B
mysqli_num_rows() C
mysqli_rows() D
mysqli_fetch_count()
Analysis & Theory
`mysqli_num_rows()` returns the number of rows in a result set.
What is the best way to prevent accidental mass deletion with DELETE?
A
Never use DELETE B
Use DELETE with a WHERE clause C
Use SELECT instead D
Use DROP TABLE
Analysis & Theory
Using a WHERE clause ensures that only specific rows are deleted, preventing mass deletion.
What does this code do?
```
$sql = "SELECT name FROM users WHERE id = 1";
$result = mysqli_query($conn, $sql);
$row = mysqli_fetch_assoc($result);
echo $row['name'];
```
A
Deletes the user with id 1 B
Selects the name of the user with id 1 and displays it C
Updates the user's name D
Creates a new table
Analysis & Theory
This code selects the name from the user where id = 1 and echoes it.