PHP PDOStatement:: fetchColumn Explanation
- 2021-11-14 05:10:02
- OfStack
PDOStatement::fetchColumn
PDOStatement:: fetchColumn-Returns a separate 1 column from the next 1 row in the result set. (PHP 5 > = 5.1.0, PECL pdo > = 0.9.0)
Description
Grammar
string PDOStatement::fetchColumn ([ int $column_number = 0 ] )
Returns a separate 1 column from the next 1 row in the result set, or FALSE if it is missing.
Parameter
column_number
Return value
PDOStatement::fetchColumn()
Returns a separate 1 column from the next 1 row in the result set.
Note: If you use PDOStatement:: fetchColumn () to retrieve data, there is no way to return another column in the same row. **
Instances
Returns the first column of the next row
<?php
$sth = $dbh->prepare("SELECT name, colour FROM fruit");
$sth->execute();
/* From the following in the result set 1 Row gets the first 1 Column */
print(" From the following in the result set 1 Row gets the first 1 Columns: \n");
$result = $sth->fetchColumn();
print("name = $result\n");
print(" From the following in the result set 1 Row gets the first 2 Columns: \n");
$result = $sth->fetchColumn(1);
print("colour = $result\n");
?>
The above example outputs:
Get Column 1 from the next row in the result set:
name = lemon
Get Column 2 from the next row in the result set:
colour = red
Summarize