fluentpdo icon indicating copy to clipboard operation
fluentpdo copied to clipboard

Using PDO::FETCH_COLUMN on fetchAll

Open neto737 opened this issue 6 years ago • 1 comments

I'm not able to use PDO::FETCH_COLUMN like fetchAll in PDO.

It's used to return results in a single dimensional array instead of bi-dimensional array. It's possible to use this?

        $query = static::getInstance()->from('products')
                ->select(NULL)
                ->select('price');

        return $query->fetchAll();

It's returning something like this:

array(4) {
  [0]=>
  array(1) {
    ["price"]=>
    string(5) "31.00"
  }
  [1]=>
  array(1) {
    ["price"]=>
    string(5) "79.00"
  }
  [2]=>
  array(1) {
    ["price"]=>
    string(5) "62.00"
  }
  [3]=>
  array(1) {
    ["price"]=>
    string(5) "15.00"
  }
}

There's any way to return a one-dimensional array?

neto737 avatar May 12 '19 00:05 neto737

$stmt = $query->execute();
$this->items = $stmt->fetchAll(\PDO::FETCH_COLUMN);

azurre avatar May 04 '20 17:05 azurre