php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #70672 PDOStatement::fetchAll documentation incomplete, incorrect
Submitted: 2015-10-08 15:42 UTC Modified: 2017-10-24 08:31 UTC
Votes:3
Avg. Score:5.0 ± 0.0
Reproduced:3 of 3 (100.0%)
Same Version:3 (100.0%)
Same OS:2 (66.7%)
From: chealer at gmail dot com Assigned:
Status: Open Package: PDO related
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2015-10-08 15:42 UTC] chealer at gmail dot com
Description:
------------
PDOStatement::fetchAll is relatively flexible, but poorly documented. According to http://php.net/manual/en/pdostatement.fetchall.php the first parameter "Controls the contents of the returned array as documented in PDOStatement::fetch()."

The documentation of the fetch_style argument of PDOStatement::fetch reads:


    Controls how the next row will be returned to the caller. This value must be one of the PDO::FETCH_* constants, defaulting to value of PDO::ATTR_DEFAULT_FETCH_MODE (which defaults to PDO::FETCH_BOTH).

        PDO::FETCH_ASSOC: returns an array indexed by column name as returned in your result set

        PDO::FETCH_BOTH (default): returns an array indexed by both column name and 0-indexed column number as returned in your result set

        PDO::FETCH_BOUND: returns TRUE and assigns the values of the columns in your result set to the PHP variables to which they were bound with the PDOStatement::bindColumn() method

        PDO::FETCH_CLASS: returns a new instance of the requested class, mapping the columns of the result set to named properties in the class. If fetch_style includes PDO::FETCH_CLASSTYPE (e.g. PDO::FETCH_CLASS | PDO::FETCH_CLASSTYPE) then the name of the class is determined from a value of the first column.

        PDO::FETCH_INTO: updates an existing instance of the requested class, mapping the columns of the result set to named properties in the class

        PDO::FETCH_LAZY: combines PDO::FETCH_BOTH and PDO::FETCH_OBJ, creating the object variable names as they are accessed

        PDO::FETCH_NAMED: returns an array with the same form as PDO::FETCH_ASSOC, except that if there are multiple columns with the same name, the value referred to by that key will be an array of all the values in the row that had that column name

        PDO::FETCH_NUM: returns an array indexed by column number as returned in your result set, starting at column 0

        PDO::FETCH_OBJ: returns an anonymous object with property names that correspond to the column names returned in your result set



fetchAll returns a bidimensional array. While the values documented in fetch's manual page allow controlling the contents of child arrays, they do not mention how to control the parent array. fetchAll's manual hints on how this can be done, but does not even mention some possible values (for example PDO::FETCH_KEY_PAIR, described in http://stackoverflow.com/questions/7451126/pdo-fetchall-group-key-value-pairs-into-assoc-array and http://blog.encodez.com/blog/using-pdofetchall-examples-with-codes-and-output-results ).

The Return Values section also needs to be fixed.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-10-08 16:23 UTC] chealer at gmail dot com
-Summary: PDOStatement::fetchAll incomplete, incorrect +Summary: PDOStatement::fetchAll documentation incomplete, incorrect
 [2015-10-08 16:23 UTC] chealer at gmail dot com
> fetchAll returns a bidimensional array.

I meant it does that by default only.
 [2016-10-14 15:17 UTC] cmb@php.net
-Type: Bug +Type: Documentation Problem -Package: Documentation problem +Package: PDO Core
 [2017-10-24 08:31 UTC] kalle@php.net
-Package: PDO Core +Package: PDO related
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 23:01:34 2024 UTC