<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xml:id="pdostatement.columncount" xmlns="http://docbook.org/ns/docbook">
 <refnamediv>
  <refname>PDOStatement::columnCount</refname>
  <refpurpose>
   Returns the number of columns in the result set
  </refpurpose>
 </refnamediv>
 <refsect1 role="description">
  &reftitle.description;
  <methodsynopsis role="PDOStatement">
   <modifier>public</modifier> <type>int</type><methodname>PDOStatement::columnCount</methodname>
   <void/>
  </methodsynopsis>

  <para>
   Use <methodname>PDOStatement::columnCount</methodname> to return the number
   of columns in the result set represented by the PDOStatement object.
  </para>
  <para>
   If the PDOStatement object was returned from <methodname>PDO::query</methodname>,
   the column count is immediately available.
  </para>
  <para>
   If the PDOStatement object was returned from
   <methodname>PDO::prepare</methodname>, an accurate column count will not be
   available until you invoke <methodname>PDOStatement::execute</methodname>.
  </para>
 </refsect1>

 <refsect1 role="parameters">
  &reftitle.parameters;
  &no.function.parameters;
 </refsect1>

 <refsect1 role="returnvalues">
  &reftitle.returnvalues;
  <para>
   Returns the number of columns in the result set represented by the
   PDOStatement object, even if the result set is empty. If there is no result set,
   <methodname>PDOStatement::columnCount</methodname> returns <literal>0</literal>.
  </para>
 </refsect1>

 <refsect1 role="errors">
  &reftitle.errors;
  &pdo.errors;
 </refsect1>

 <refsect1 role="examples">
  &reftitle.examples;
  <para>
   <example>
    <title>Counting columns</title>
    <para>
     This example demonstrates how <methodname>PDOStatement::columnCount</methodname>
     operates with and without a result set.
    </para>
    <programlisting role="php">
<![CDATA[
<?php
$dbh = new PDO('odbc:sample', 'db2inst1', 'ibmdb2');

$sth = $dbh->prepare("SELECT name, colour FROM fruit");

/* Count the number of columns in the (non-existent) result set */
$colcount = $sth->columnCount();
print("Before execute(), result set has $colcount columns (should be 0)\n");

$sth->execute();

/* Count the number of columns in the result set */
$colcount = $sth->columnCount();
print("After execute(), result set has $colcount columns (should be 2)\n");

?>
]]>
    </programlisting>
    &example.outputs;
    <screen>
<![CDATA[
Before execute(), result set has 0 columns (should be 0)
After execute(), result set has 2 columns (should be 2)
]]>
    </screen>
   </example>
  </para>
 </refsect1>


 <refsect1 role="seealso">
  &reftitle.seealso;
  <para>
   <simplelist>
    <member><methodname>PDO::prepare</methodname></member>
    <member><methodname>PDOStatement::execute</methodname></member>
    <member><methodname>PDOStatement::rowCount</methodname></member>
   </simplelist>
  </para>
 </refsect1>

</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->
