Skip to content

Latest commit

 

History

History
55 lines (41 loc) · 1.33 KB

pdostatement-columncount.md

File metadata and controls

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