stmtfetchAllPDO
stmtfetchAllPDO refers to the fetchAll method of a PDOStatement in PHP's PDO extension. It retrieves all remaining rows from a previously executed query and returns them as an array. By default, if no fetch style is provided, fetchAll uses a mixed structural format, commonly including both associative and numeric indices for each row (PDO::FETCH_BOTH), but the exact shape depends on the chosen fetch style.
The method signature accepts three parameters: fetch_style, fetch_argument, and ctor_args. The fetch_style determines how rows are
- PDO::FETCH_ASSOC: each row as an associative array keyed by column name.
- PDO::FETCH_NUM: each row as a numeric array indexed by column number.
- PDO::FETCH_BOTH: each row includes both associative and numeric indices.
- PDO::FETCH_OBJ: each row as an anonymous object with properties matching column names.
- PDO::FETCH_COLUMN: returns a single column; fetch_argument selects the column index or name.
- PDO::FETCH_CLASS: returns instances of a specified class; fetch_argument is the class name, and ctor_args supplies constructor
- Retrieve all rows as associative arrays: $rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
- Retrieve a single column: $ids = $stmt->fetchAll(PDO::FETCH_COLUMN, 0);
- Retrieve as objects of a class: $users = $stmt->fetchAll(PDO::FETCH_CLASS, 'User', array('defaultRole'));
Performance and memory considerations:
fetchAll loads all remaining rows into memory. For large result sets, this can consume substantial memory.
If no rows remain, fetchAll returns an empty array. Error handling depends on the PDO error mode;