title | description | author | ms.author | ms.date | ms.service | ms.subservice | ms.topic |
---|---|---|---|---|---|---|---|
PDOStatement::fetchColumn |
API reference for the PDOStatement::fetchColumn function in the Microsoft PDO_SQLSRV Driver for PHP for SQL Server. |
David-Engel |
davidengel |
08/10/2020 |
sql |
connectivity |
reference |
[!INCLUDEDriver_PHP_Download]
Returns one column in a row.
string PDOStatement::fetchColumn ([ $column_number ] );
$column_number: An optional integer indicating the zero-based column number. The default is 0 (the first column in the row).
One column or false if there are no more rows.
Support for PDO was added in version 2.0 of the [!INCLUDEssDriverPHP].
<?php
$server = "(local)";
$database = "AdventureWorks";
$conn = new PDO( "sqlsrv:server=$server ; Database = $database", "", "");
$stmt = $conn->query( "select * from Person.ContactType where ContactTypeID < 5 " );
while ( $result = $stmt->fetchColumn(1)) {
print($result . "\n");
}
?>