php-doc-en/reference/pdo/functions/PDOStatement-columnCount.xml
Wez Furlong 34a6bc84d6 All these methods are stable.
Note: getColumnMeta is not stable; the warning was intentionally left there.


git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@195768 c90b9560-bf6c-de11-be94-00142212c4b1
2005-09-11 06:22:26 +00:00

115 lines
3.1 KiB
XML

<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.2 $ -->
<!-- Generated by xml_proto.php v2.2. Found in /scripts directory of phpdoc. -->
<refentry id="function.PDOStatement-columnCount">
<refnamediv>
<refname>PDOStatement::columnCount</refname>
<refpurpose>
Returns the number of columns in the result set
</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<type>int</type><methodname>PDOStatement::columnCount</methodname>
<void />
</methodsynopsis>
<para>
Use <function>PDOStatement::columnCount</function> to return the number
of columns in the result set represented by the PDOStatement object.
</para>
<para>
If the PDOStatement object was returned from <function>PDO::query</function>,
the column count is immediately available.
</para>
<para>
If the PDOStatement object was returned from
<function>PDO::prepare</function>, an accurate column count will not be
available until you invoke <function>PDOStatement::execute</function>.
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
Returns the number of columns in the result set represented by the
PDOStatement object. If there is no result set,
<function>PDOStatement::columnCount</function> returns <literal>0</literal>.
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title>Counting columns</title>
<para>
This example demonstrates how <function>PDOStatement::columnCount</function>
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><function>PDO::prepare</function></member>
<member><function>PDOStatement::execute</function></member>
<member><function>PDOStatement::rowCount</function></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:"../../../../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
-->