# Retrieving Query Results with TiDB
+ Use **`fetch([$fetch_style])`** to retrieve rows from the result set as an array of column values
+ `$fetch_style` include:
    + **`PDO::FETCH_NUM`**: Returns an array. You access the elements of the array with a numeric subscript
    + **`PDO::FETCH_ASSOC`**: Returns an associative array indexed by column name
    + **`PDO::FETCH_BOTH`**: The default. Returns an array that is accessible by either numeric subscript or column name
    + **`PDO::FETCH_OBJ`**: Returns an object with members that correspond to column names
+ Use **`setFetchMode($fetch_style)`** to specify the fetch style for all subsequent fetches from the statement handle
+ Use **`columnCount()`** to return the number of columns
+ Use **`fetchAll()`** to return an array of rows
--------------------------------------------------------
When you retrieve data from the TiDB server using the database handle's `query()` method, the result set is returned as a `PDOStatement` object. Store this object in a variable, which then becomes the `statement handle` that you use to interact with the result set. 

To access individual row within the result set, use the `fetch()` method.

PDO provides many options for fetching rows, known as fetch styles. If you do not specify a fetch style when calling `fetch()`, the default is `PDO::FETCH_BOTH`, which returns an array, and you can access its elements by either a numeric subscript or by the column name.

To use the same fetch style for every fetch from a particular statement handle, call the `setFetchMode($fetch_style)` method before you execute the first `fetch()`. If you want to use the same fetch style for every fetch within a database connection, use the database handle's `setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, $fetch_style)` method.

Instead of retrieving individual rows within a loop construct, use `fetchAll()` to retrieve an array of rows. The array represents each row as either an array of column values or an object with properties corresponding to each column name (depending on the fetch style you specify). It returns an empty array if there are no results or `false` if it fails. 

Fetching large result sets this way places heavy demands on your application. Consider using the database server to filter the results as much as possible before retrieving and processing them with PHP.

