Skip to content

Latest commit

 

History

History
55 lines (41 loc) · 1.33 KB

File metadata and controls

55 lines (41 loc) · 1.33 KB
title PDOStatement::columnCount
description API reference for the PDOStatement::columnCount function in the Microsoft PDO_SQLSRV Driver for PHP for SQL Server.
author David-Engel
ms.author davidengel
ms.date 08/10/2020
ms.service sql
ms.subservice connectivity
ms.topic reference

PDOStatement::columnCount

[!INCLUDEDriver_PHP_Download]

Returns the number of columns in a result set.

Syntax

  
int PDOStatement::columnCount ();  

Return Value

Returns the number of columns in a result set. Returns zero if the result set is empty.

Remarks

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

Example

<?php  
$database = "AdventureWorks";  
$server = "(local)";  
$conn = new PDO( "sqlsrv:server=$server ; Database = $database", "", "");  
  
$query = "select * from Person.ContactType";  
$stmt = $conn->prepare( $query );  
print $stmt->columnCount();   // 0  
  
echo "\n";  
$stmt->execute();  
print $stmt->columnCount();  
  
echo "\n";  
$stmt = $conn->query("select * from HumanResources.Department");  
print $stmt->columnCount();  
?>  

See Also

PDOStatement Class

PDO