diff --git a/lib/Doctrine/DBAL/Statement.php b/lib/Doctrine/DBAL/Statement.php index 15cf41f4559..409b30681a9 100644 --- a/lib/Doctrine/DBAL/Statement.php +++ b/lib/Doctrine/DBAL/Statement.php @@ -203,13 +203,13 @@ public function fetch($fetchStyle = PDO::FETCH_BOTH) * Returns an array containing all of the result set rows. * * @param integer $fetchStyle - * @param integer $columnIndex + * @param mixed $fetchArgument * @return array An array containing all of the remaining rows in the result set. */ - public function fetchAll($fetchStyle = PDO::FETCH_BOTH, $columnIndex = 0) + public function fetchAll($fetchStyle = PDO::FETCH_BOTH, $fetchArgument = 0) { - if ($columnIndex != 0) { - return $this->stmt->fetchAll($fetchStyle, $columnIndex); + if ($fetchArgument !== 0) { + return $this->stmt->fetchAll($fetchStyle, $fetchArgument); } return $this->stmt->fetchAll($fetchStyle); } diff --git a/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php b/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php index 0553b45218d..02ffeec8aa9 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php @@ -380,4 +380,38 @@ public function testSetDefaultFetchMode() $row = array_keys($stmt->fetch()); $this->assertEquals(0, count( array_filter($row, function($v) { return ! is_numeric($v); })), "should be no non-numerical elements in the result."); } + + /** + * @group DBAL-196 + */ + public function testFetchAllSupportFetchClass() + { + $this->_conn->executeQuery('DELETE FROM fetch_table')->execute(); + $this->_conn->insert('fetch_table', array( + 'test_int' => 1, + 'test_string' => 'foo', + 'test_datetime' => '2010-01-01 10:10:10' + )); + + $sql = "SELECT test_int, test_string, test_datetime FROM fetch_table"; + $stmt = $this->_conn->prepare($sql); + $stmt->execute(); + + $results = $stmt->fetchAll( + \PDO::FETCH_CLASS, + __NAMESPACE__.'\\MyFetchClass' + ); + + $this->assertEquals(1, count($results)); + $this->assertInstanceOf(__NAMESPACE__.'\\MyFetchClass', $results[0]); + + $this->assertEquals(1, $results[0]->test_int); + $this->assertEquals('foo', $results[0]->test_string); + $this->assertEquals('2010-01-01 10:10:10', $results[0]->test_datetime); + } +} + +class MyFetchClass +{ + public $test_int, $test_string, $test_datetime; }