From 8c024a2292d1cab736241c087b773ad539bb3fd7 Mon Sep 17 00:00:00 2001 From: Moshe Brevda Date: Thu, 8 Jan 2015 23:38:21 +0200 Subject: [PATCH] Changed third param to be fetch style --- README.md | 4 ++-- src/ExtendedPdo.php | 15 ++++----------- tests/unit/src/AbstractExtendedPdoTest.php | 2 +- 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index f8ea1430..485eb737 100644 --- a/README.md +++ b/README.md @@ -231,9 +231,9 @@ $result = $pdo->fetchAssoc($stm, $bind); // fetchGroup() is like fetchAssoc() except that the values aren't wrapped in // arrays. Instead, single column values are returned as a single dimensional // array and multiple columns are returned as an array of arrays -// Third column specifies if more than a single column is to be returned +// Set style to PDO::FETCH_NAMED when values are an array // (i.e. there are more than two columns in the select) -$result = $pdo->fetchGroup($stm, $bind, $singleColumn = true) +$result = $pdo->fetchGroup($stm, $bind, $style = PDO::FETCH_COLUMN) // fetchObject() returns the first row as an object of your choosing; the // columns are mapped to object properties. an optional 4th parameter array diff --git a/src/ExtendedPdo.php b/src/ExtendedPdo.php index b880d9b3..979ab22e 100644 --- a/src/ExtendedPdo.php +++ b/src/ExtendedPdo.php @@ -567,7 +567,8 @@ public function fetchValue($statement, array $values = array()) * * @param array $values Values to bind to the query. * - * @param bool $singleColoumn If the array value should also be an array + * @param int $style a fetch style defaults to PDO::FETCH_COLUMN for single + * values, use PDO::FETCH_NAMED when fetching a multiple columns * * @return array * @@ -575,18 +576,10 @@ public function fetchValue($statement, array $values = array()) public function fetchGroup( $statement, array $values = array(), - $singleColumn = true + $style = self::FETCH_COLUMN ) { - $args = self::FETCH_GROUP; - - if ($singleColumn) { - $args = $args | self::FETCH_COLUMN; - } else { - $args = $args | self::FETCH_NAMED; - } - $sth = $this->perform($statement, $values); - return $sth->fetchAll($args); + return $sth->fetchAll(self::FETCH_GROUP | $style); } /** diff --git a/tests/unit/src/AbstractExtendedPdoTest.php b/tests/unit/src/AbstractExtendedPdoTest.php index fb9753de..822d5474 100755 --- a/tests/unit/src/AbstractExtendedPdoTest.php +++ b/tests/unit/src/AbstractExtendedPdoTest.php @@ -378,7 +378,7 @@ public function testGroupSingleColumn() public function testGroupArray() { $stm = "SELECT id, name FROM pdotest WHERE id = 1"; - $actual = $this->pdo->fetchGroup($stm, array(), false); + $actual = $this->pdo->fetchGroup($stm, array(), PDO::FETCH_NAMED); $expect = array( '1' => array( array(