tags:

views:

225

answers:

3

What's the difference between

$PDOStatement->fetchColumn();

and

$PDOStatement->fetch(PDO::FETCH_COLUMN);

(if one exists)? Or are they functionally similar but only aesthetically different?

+2  A: 

By default fetchColumn() will return only 'value' while other by default will return array('column_name'=>'value'). You'd have to use setFetchMode() to change that.

$PDOStatement->fetchColumn($colno);

would be equivalent to:

$PDOStatement->setFetchMode(PDO::FETCH_COLUMN, $colno);
$PDOStatement->fetch();
vartec
A: 

From the doc here for fetch, there doesn't seem to be a PDO::FETCH_COLUMN style. If that's true, then the difference is fetch will return a row, while fetchColumn will only return the specified column.

Magic Hat
+1  A: 

By default fetchColumn() will return only 'value' while other by default will return array('column_name'=>'value'). You'd have to use setFetchMode() to change that.

literally copied from the chosen answer.
Alister Bulman