PDOStatement::columnCount
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 Microsoft Drivers for PHP for SQL Server.
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();
?>