Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PDOStatement::fetchColumn

PDOStatement::fetchColumn

PHP PDO Reference ManualPHP 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 the result set, or FALSE if there are no more rows.


Parameters

** column_number**

The index number of the column you wish to retrieve from the row (0-indexed). If no value is supplied, PDOStatement::fetchColumn() fetches the first column.


Return Value

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

Note:If you use PDOStatement::fetchColumn() to retrieve data, there is no way to return another column from the same row.

**


Example

Return the first column of the next row

prepare("SELECT name, colour FROM fruit");

$sth->execute();

/* 从结果集中的下一行获取第一列 */ print("从结果集中的下一行获取第一列:\n"); $result = $sth->fetchColumn(); print("name = $result\n");

print("从结果集中的下一行获取第二列:\n"); $result = $sth->fetchColumn(1); print("colour = $result\n"); ?>

The above example will output:

从结果集中的下一行获取第一列:

name = lemon

Get the second column from the next row in the result set:

colour = red


PHP PDO Reference ManualPHP PDO Reference Manual

**