Recall & Review
beginner
What does the
fetch() method do in PHP PDO?The
fetch() method retrieves the next row from a result set as an array or object. It returns one row at a time or false if no more rows are available.Click to reveal answer
beginner
How is
fetchAll() different from fetch()?fetchAll() retrieves all remaining rows from the result set at once as an array of arrays or objects, while fetch() gets one row at a time.Click to reveal answer
intermediate
What is a common use case for
fetch()?Use
fetch() when you want to process rows one by one, for example, in a loop to handle large data sets without loading everything into memory.Click to reveal answer
beginner
What does
fetchAll(PDO::FETCH_ASSOC) return?It returns all rows as an array of associative arrays, where each array uses column names as keys.
Click to reveal answer
beginner
What happens if you call
fetch() after all rows have been fetched?It returns
false, indicating there are no more rows to fetch.Click to reveal answer
Which method fetches all rows from a PDO statement at once?
✗ Incorrect
fetchAll() retrieves all rows at once, while fetch() retrieves one row at a time.What does
fetch() return when no more rows are available?✗ Incorrect
fetch() returns false when there are no more rows to fetch.Which fetch style returns rows as associative arrays with column names as keys?
✗ Incorrect
PDO::FETCH_ASSOC returns rows as associative arrays keyed by column names.When is it better to use
fetch() instead of fetchAll()?✗ Incorrect
fetch() is better for large data sets to avoid loading all rows into memory at once.What type of value does
fetchAll() return?✗ Incorrect
fetchAll() returns an array containing all rows from the result set.Explain the difference between
fetch() and fetchAll() in PHP PDO.Think about how many rows each method returns and memory usage.
You got /4 concepts.
Describe a scenario where using
fetch() is better than fetchAll().Consider memory and performance when handling many rows.
You got /4 concepts.