Latest web development tutorials

PDOStatement :: fetchColumn

PHP PDO Reference Manual PHP PDO Reference Manual

PDOStatement :: fetchColumn - from the next row in the result set to return a single one. (PHP 5> = 5.1.0, PECL pdo> = 0.9.0)


Explanation

grammar

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

The next row from the result set to return a single one, if not, it returns FALSE.


parameter

column_number

Do you want to retrieve from the line in the column index number (0-based index). If no value is PDOStatement :: fetchColumn () Gets the first column.


return value

PDOStatement :: fetchColumn () from the next row in the result set to return a single one.

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


Examples

Return to the first column of the next row

<?php
$sth = $dbh->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 examples will output:

从结果集中的下一行获取第一列:
name = lemon
从结果集中的下一行获取第二列:
colour = red

PHP PDO Reference Manual PHP PDO Reference Manual