Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What all fetch modes are there for PDO?

Tags:

php

pdo

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?

like image 260
JD Isaacks Avatar asked Sep 07 '10 17:09

JD Isaacks


People also ask

What is the use of fetch_group in PDO?

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().

What is the mode parameter in a PDO?

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

What is the value of fetch_Func in PDO?

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.

Is there a way to retrieve first column from result using PDO?

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.


1 Answers

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

like image 170
prodigitalson Avatar answered Sep 20 '22 17:09

prodigitalson