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?
✗ Incorrect
PDO::FETCH_OBJ returns each row as an object with properties named after the columns.If you want to fetch data as an array indexed by column names only, which fetch mode should you use?
✗ Incorrect
PDO::FETCH_ASSOC returns an associative array indexed by column names.What does
PDO::FETCH_NUM return?✗ Incorrect
PDO::FETCH_NUM returns an array indexed by column numbers (0-based).Which fetch mode allows you to fetch data directly into a user-defined class?
✗ Incorrect
PDO::FETCH_CLASS maps the row data into an instance of a specified class.When would you use
PDO::FETCH_COLUMN?✗ Incorrect
PDO::FETCH_COLUMN fetches only one column from each row, useful for lists of values.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.