php-doc-en/reference/pdo/pdostatement/columncount.xml
George Peter Banyard 3d69f8f11f
Fix most missing param sections for PDO
Also rearange changelog before examples for one file

Part of #658
2021-06-13 19:24:31 +01:00

119 lines
3.2 KiB
XML

<?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>
<modifier>public</modifier> <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="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,
<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:"~/.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
-->