Store query result on an array
Here you can replace $sql with $result.

&lt;?php
// Retrieve all records into an indexed array of stdClass objects.
$result-&gt;fetchAll();

// Retrieve all records into an associative array keyed by the field in the result specified.
$result-&gt;fetchAllAssoc($field);

// Retrieve a 2-column result set as an associative array of field 0 =&gt; field 1.
$result-&gt;fetchAllKeyed();
// You can also specify which two fields to use by specifying the column numbers for each field
$result-&gt;fetchAllKeyed(0,2); // would be field 0 =&gt; field 2
$result-&gt;fetchAllKeyed(1,0); // would be field 1 =&gt; field 0
// If you need an array where keys and values contain the same field (e.g. for creating a 'checkboxes' form element), the following is a perfectly valid method:
$result-&gt;fetchAllKeyed(0,0); // would be field 0 =&gt; field 0, e.g. [article] =&gt; [article]

// Retrieve a 1-column result set as one single array.
$result-&gt;fetchCol();
// Column number can be specified otherwise defaults to first column
$result-&gt;fetchCol($column_index);
?&gt;