To retrieve data in PDO, we use the query() method (for simple queries) or prepared statements. We
then process the results using the fetchAll() method, which returns all rows at once in the form of an
array.
By using the PDO::FETCH_ASSOC mode, we ensure that the results are returned as an associative array,
where the keys match the column names in the database (e.g., $row["name"]). In the example below, we will output all
users from our table.
query() method is suitable for queries without external parameters.fetchAll() is ideal for small to medium-sized data sets.foreach loop for an elegant iteration through all retrieved rows.