0
0
PHPprogramming~5 mins

Fetching results (fetch, fetchAll) in PHP - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
Aprepare()
Bfetch()
Cexecute()
DfetchAll()
What does fetch() return when no more rows are available?
Afalse
Bnull
Cempty array
D0
Which fetch style returns rows as associative arrays with column names as keys?
APDO::FETCH_NUM
BPDO::FETCH_OBJ
CPDO::FETCH_ASSOC
DPDO::FETCH_BOTH
When is it better to use fetch() instead of fetchAll()?
AWhen you want all rows at once
BWhen processing large data sets row by row
CWhen you want to prepare a statement
DWhen you want to execute a query
What type of value does fetchAll() return?
AAn array of rows
BAn integer
CA boolean
DA single row
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.