Bug #70672 [Opn]: PDOStatement::fetchAll documentation incomplete, incorrect
| From: | chealer at gmail dot com | Date: | Thu, 08 Oct 2015 16:23:16 +0000 |
| Subject: | Bug #70672 [Opn]: PDOStatement::fetchAll documentation incomplete, incorrect | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-12813@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=70672&edit=1
ID: 70672
User updated by: chealer at gmail dot com
Reported by: chealer at gmail dot com
-Summary: PDOStatement::fetchAll incomplete, incorrect
+Summary: PDOStatement::fetchAll documentation incomplete,
incorrect
Status: Open
Type: Bug
Package: Documentation problem
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
> fetchAll returns a bidimensional array.
I meant it does that by default only.
Previous Comments:
------------------------------------------------------------------------
[2015-10-08 15:42:40] 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.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=70672&edit=1