In the PDO, the
setFetchMode method is used to define how the data is obtained, in the case of the example you posted, the
PDO::ASSOC constant is used to return the data in an associative array.
fetch/fetchAll methods with the
PDO::ASSOC parameter will get the data of a query in an associative array (because it uses the constant in question), in which case the method itself is specifying directly how the data will be returned. Generally, this is only necessary when the PDO was not preconfigured with
In case a return type is set with setFetchMode, the parameter passed to fetch / fetchAll is no longer accurate. That is, setFetchMode sets the default way to get the data so you do not have to specify it later.