I am just getting started using PDO.
I am wondering if there is a list of all the available FETCH_* modes and what each does?
I found this page of the manuals that covers setFetchMode
which even has this line in it:
The fetch mode must be one of the PDO::FETCH_* constants.
But I see nothing that lists what all is available?
PDO::FETCH_GROUP. This mode groups the returned rows into a nested array, where indexes will be unique values from the first column, and values will be arrays similar to ones returned by regular fetchAll().
The mode parameter determines how PDO returns the row. 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
For example, PDO::FETCH_FUNC has a bit unexpected value of 10 (which is equal to PDO::FETCH_CLASS|PDO::FETCH_ASSOC combination - though quite useless by itself). For starter let's list the modes that resemble the behavior of old good mysql functions.
note that fetch constants are not included in the PDO class for PHP versions prior to 5.1 I could use PDO::FETCH_COLUMN to retrieve the first column from result. Worked on Postgresql with PHP 5.3.10.
http://www.php.net/manual/en/pdo.constants.php will tell you all he constants, including the fetch mode constants. You can also find more details in the PDOStatement::fetch
documentation: http://www.php.net/manual/en/pdostatement.fetch.php
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With