Recall & Review
beginner
What does the
query method do in PHP's mysqli?The
query method sends an SQL query to the database and returns the result set or false if the query fails.Click to reveal answer
beginner
How do you check if a
query was successful in PHP?You check if the result of
$mysqli->query() is not false. If it is false, the query failed.Click to reveal answer
beginner
What type of value does
query return for a SELECT statement?It returns a
mysqli_result object which you can use to fetch rows from the result set.Click to reveal answer
beginner
What does
query return for an INSERT, UPDATE, or DELETE statement?It returns
true if the query was successful, or false if it failed.Click to reveal answer
beginner
How do you fetch rows from the result of a
query?Use methods like
fetch_assoc() on the mysqli_result object to get rows as associative arrays.Click to reveal answer
What does
$mysqli->query() return when a SELECT query is successful?✗ Incorrect
For SELECT queries,
query returns a mysqli_result object to fetch rows.What does
$mysqli->query() return when an INSERT query is successful?✗ Incorrect
For INSERT, UPDATE, DELETE queries,
query returns true on success.How can you check if a query failed?
✗ Incorrect
If
query returns false, the query failed.Which method do you use to get rows from a
mysqli_result object?✗ Incorrect
Use
fetch_assoc() to get rows as associative arrays.What happens if you run
query with a wrong SQL syntax?✗ Incorrect
If the SQL syntax is wrong,
query returns false.Explain how to use the
query method to run a SELECT statement and get results.Think about sending the query, checking success, and reading rows.
You got /3 concepts.
Describe what the
query method returns for different types of SQL statements.Consider the difference between queries that return data and those that just change data.
You got /3 concepts.