Vaindil Vaindil - 3 months ago 14
MySQL Question

Fetching multiple columns of a database

I needed to grab one full column of a database and only that column, and have it returned as an array. I was using

$qarr1 = $stmt->fetchAll(PDO::FETCH_COLUMN);
, which worked perfectly. I now need to pull a second column from that data and have it saved as a separate array, but I can't use
for this because of cursor problems. I am still brand new to PHP and don't quite understand the whole concept of the cursor, and I'm having difficulty understanding the arguments for
. Is someone able to explain what I could do instead of using


You could try using $stmt->fetchAll(PDO::FETCH_ASSOC); but if you really want to avoid fetchAll() then just loop through each row.

$arr = array();
while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
  $arr[] = $row;