Easy Tutorial
❮ Func Ftp Put Php Switch ❯

PDOStatement::fetchColumn

PHP PDO Reference Manual

PDOStatement::fetchColumn — Returns a single column from the next row of a result set. (PHP 5 >= 5.1.0, PECL pdo >= 0.9.0)


Description

Syntax

string PDOStatement::fetchColumn ([ int $column_number = 0 ] )

Returns a single column from the next row of a result set, or FALSE if there are no more rows.


Parameters

column_number

The index number of the column you want to retrieve from the row (zero-based index). If no value is provided, PDOStatement::fetchColumn() fetches the first column.


Return Value

PDOStatement::fetchColumn() returns a single column from the next row of a result set.

Note:


Examples

Return the first column of the next row

<?php
$sth = $dbh->prepare("SELECT name, colour FROM fruit");
$sth->execute();

/* Fetch the first column from the next row of the result set */
print("Fetch the first column from the next row of the result set:\n");
$result = $sth->fetchColumn();
print("name = $result\n");

print("Fetch the second column from the next row of the result set:\n");
$result = $sth->fetchColumn(1);
print("colour = $result\n");
?>

The above example will output:

Fetch the first column from the next row of the result set:
name = lemon
Fetch the second column from the next row of the result set:
colour = red

PHP PDO Reference Manual

❮ Func Ftp Put Php Switch ❯