下面例子演示如何使用 PDOStatement::columnCount() 操作一个结果集和一个空集。
<?php
$dbh = new PDO('odbc:sample', 'db2inst1', 'ibmdb2');
$sth = $dbh->prepare("SELECT name, colour FROM fruit");
/* 计算一个(不存在)的结果集中的列数 */
$colcount = $sth->columnCount();
print("Before execute(), result set has $colcount columns (should be 0)\n");
$sth->execute();
/* 计算结果集中的列数 */
$colcount = $sth->columnCount();
print("After execute(), result set has $colcount columns (should be 2)\n");
?>
Before execute(), result set has 0 columns (should be 0)
After execute(), result set has 2 columns (should be 2)