PDOATTRDEFAULTFETCHMODE
PDOATTRDEFAULTFETCHMODE is a constant defined in PHP's PDO (PHP Data Objects) extension. It specifies the default fetch mode that PDO should use when retrieving query results. The fetch mode determines how each row returned by a SELECT statement is represented in PHP, such as an array, an object, or a single column value.
The constant is used in the setAttribute() method of a PDO instance to set the default fetch
$pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
After this call, all subsequent fetches performed on that PDO object without specifying a mode will return
FETCH_DEFAULT – Uses the default fetch mode of the database driver.
FETCH_ASSOC – Returns an associative array indexed by column name.
FETCH_NUM – Returns a numerically indexed array.
FETCH_BOTH – Returns an array indexed by both column name and numeric position.
FETCH_OBJ – Returns an anonymous object with property names that correspond to the column names.
FETCH_CLASS – Returns an instance of a specified class populated with column values.
Choosing an appropriate default fetch mode helps maintain consistent data handling across an application. It reduces