Skip to content

Latest commit

 

History

History
54 lines (41 loc) · 1.37 KB

File metadata and controls

54 lines (41 loc) · 1.37 KB
title PDOStatement::fetchColumn | Microsoft Docs
ms.custom
ms.date 01/19/2017
ms.prod sql
ms.prod_service connectivity
ms.reviewer
ms.technology connectivity
ms.topic conceptual
ms.assetid 6ebf385c-ddb0-4c53-9dc6-7df0d3740b04
author David-Engel
ms.author v-daenge

PDOStatement::fetchColumn

[!INCLUDEDriver_PHP_Download]

Returns one column in a row.

Syntax

  
string PDOStatement::fetchColumn ([ $column_number ] );  

Parameters

$column_number: An optional integer indicating the zero-based column number. The default is 0 (the first column in the row).

Return Value

One column or false if there are no more rows.

Remarks

Support for PDO was added in version 2.0 of the [!INCLUDEssDriverPHP].

Example

<?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");   
   }  
?>  

See Also

PDOStatement Class

PDO