Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

PDOStatement::fetchColumn

SQL Server 2008 R2

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 Microsoft Drivers for PHP for SQL Server.

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

Reference

Other Resources

PDO
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.