public function DatabaseStatementInterface::fetchCol

You are here

7 database.inc public DatabaseStatementInterface::fetchCol($index = 0)

Returns an entire single column of a result set as an indexed array.

Note that this method will run the result set to the end.

Parameters

$index: The index of the column number to fetch.

Return value

An indexed array, or an empty array if there is no result set.

3 methods override DatabaseStatementInterface::fetchCol()
DatabaseStatementBase::fetchCol in includes/database/database.inc
Returns an entire single column of a result set as an indexed array.
DatabaseStatementEmpty::fetchCol in includes/database/database.inc
Returns an entire single column of a result set as an indexed array.
DatabaseStatementPrefetch::fetchCol in includes/database/prefetch.inc
Returns an entire single column of a result set as an indexed array.

File

includes/database/database.inc, line 2084
Core systems for the database layer.

Class

DatabaseStatementInterface
Represents a prepared statement.

Code

public function fetchCol($index = 0);

Comments

See the other DatabaseStatementInterface methods here:
http://api.drupal.org/api/drupal/includes!database!database.inc/interfac...

It would be v useful and trivial to implement a 2nd, optional parameter so you could fetch the values of one column keyed by the values of another.

Without this I'm resorting to fetchAllAssoc($key_column), then looping to replace the StdClass objects created with the value needed. Seems messy.