PDOStatement::fetchColumn — Returns a single column from the next row in the result set. (PHP 5 >= 5.1.0, PECL pdo >= 0.9.0)
string PDOStatement::fetchColumn ([ int $column_number = 0 ] )
Returns a single column from the next row in the result set, or FALSE if there is no more.
column_number
The index number (0-based index) of the column you want to retrieve from the row. If no value is provided, PDOStatement::fetchColumn() fetches the first column.
PDOStatement::fetchColumn() returns a single column from the next row in the result set.
Note: If you use PDOStatement::fetchColumn() to retrieve data, there is no way to return another column of the same row.
<?php$sth = $dbh->prepare("SELECT name, color FROM fruit");$sth->execute();/* Get the first column from the next row in the result set*/print("From the result set Get the first column on the next line:n");$result = $sth->fetchColumn();print("name = $resultn");print("Get the second column from the next row in the result set:n");$result = $sth->fetchColumn(1);print("colour = $resultn"); ?>
The above example will output:
Get the first column from the next row in the result set: name = lemon Get the second column from the next row in the result set: color = red