Performance of loading fields
I'd imagine a $stmt-&gt;fetchAll() would be more performant than the while-loop and $stmt-&gt;fetch(). Rather than paging over an entire set of records one at a time, try returning the results from the database in-bulk. Your code is making a trip to the database with each iteration of your while loop. Your code will still look virtually identical:

$i = 0;
$r = $stmt-&gt;fetchAll();
foreach ($r as $data) {
    $array[$i] = array();
    foreach ($data as $k =&gt; $v) {
        $array[$i][$k] = $v;
    }
    $i++;
}  


If you're using mysqli (native driver only), and not PDO's MySQL, you could do this:

$i = 0;
$r = $stmt-&gt;get_result();
$r = $r-&gt;fetchAll();
foreach ($r as $data) {
    $array[$i] = array();
    foreach ($data as $k =&gt; $v) {
        $array[$i][$k] = $v;
    }
    $i++;
}  


You shouldn't worry about loops per se, but performance hits that you see, whether they come from loops or not. This is only possible if you're profiling your code.