0
0
PHPprogramming~5 mins

Fetch modes and styles in PHP - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the default fetch mode in PHP's PDO when retrieving data?
The default fetch mode is PDO::FETCH_BOTH, which returns an array indexed by both column name and number.
Click to reveal answer
beginner
Explain PDO::FETCH_ASSOC fetch mode.
PDO::FETCH_ASSOC returns an array indexed by column names only, which helps avoid duplicate data and is memory efficient.
Click to reveal answer
intermediate
What does PDO::FETCH_OBJ do when fetching data?
It returns each row as an anonymous object where columns are accessible as properties, e.g., $row->columnName.
Click to reveal answer
intermediate
How does PDO::FETCH_CLASS differ from other fetch modes?
It fetches data into an instance of a specified class, mapping columns to class properties, allowing object-oriented data handling.
Click to reveal answer
intermediate
What is the purpose of PDO::FETCH_COLUMN?
It fetches only a single column from the next row in the result set, useful when you need just one column's data.
Click to reveal answer
Which fetch mode returns data as an object with properties matching column names?
APDO::FETCH_COLUMN
BPDO::FETCH_ASSOC
CPDO::FETCH_NUM
DPDO::FETCH_OBJ
If you want to fetch data as an array indexed by column names only, which fetch mode should you use?
APDO::FETCH_BOTH
BPDO::FETCH_NUM
CPDO::FETCH_ASSOC
DPDO::FETCH_CLASS
What does PDO::FETCH_NUM return?
AAn array indexed by column numbers
BA class instance
CAn object with column properties
DAn array indexed by column names
Which fetch mode allows you to fetch data directly into a user-defined class?
APDO::FETCH_OBJ
BPDO::FETCH_CLASS
CPDO::FETCH_ASSOC
DPDO::FETCH_COLUMN
When would you use PDO::FETCH_COLUMN?
ATo fetch a single column from each row
BTo fetch data as an object
CTo fetch all columns as an associative array
DTo fetch data as a numeric array
Describe the main differences between PDO::FETCH_ASSOC, PDO::FETCH_NUM, and PDO::FETCH_BOTH.
Think about how the data is indexed in the returned array.
You got /3 concepts.
    Explain how PDO::FETCH_CLASS can be used to work with database results in an object-oriented way.
    Consider how this fetch mode helps organize data as objects.
    You got /3 concepts.