Files
php-doc-ru/reference/pdo/pdostatement/columncount.xml
2021-06-15 11:13:25 +03:00

124 lines
4.2 KiB
XML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?xml version="1.0" encoding="utf-8"?>
<!-- EN-Revision: 3d69f8f11fcade2ce4fd908d176cbf874603fe57 Maintainer: tmn Status: ready -->
<!-- Reviewed: yes -->
<!-- $Revision$ -->
<refentry xml:id="pdostatement.columncount" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>PDOStatement::columnCount</refname>
<refpurpose>
Возвращает количество столбцов в результирующем наборе
</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<modifier>public</modifier> <type>int</type><methodname>PDOStatement::columnCount</methodname>
<void/>
</methodsynopsis>
<para>
Используйте <function>PDOStatement::columnCount</function>, чтобы узнать
количество столбцов в результирующем наборе, который представляет объект
PDOStatement.
</para>
<para>
Если объект PDOStatement был возвращён из метода <function>PDO::query</function>,
число столбцов можно узнать сразу же.
</para>
<para>
Если объект PDOStatement был возвращён из метода
<function>PDO::prepare</function>, точное количество столбцов можно будет
узнать только после запуска метода <function>PDOStatement::execute</function>.
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
&no.function.parameters;
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
Возвращает количество столбцов в результирующем наборе запроса
PDOStatement, даже если он пуст. Если результирующего набора нет,
<function>PDOStatement::columnCount</function> возвращает <literal>0</literal>.
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title>Подсчёт столбцов</title>
<para>
В этом примере показано, как <function>PDOStatement::columnCount</function>
работает в случае наличия и отсутствия результирующего набора.
</para>
<programlisting role="php">
<![CDATA[
<?php
$dbh = new PDO('odbc:sample', 'db2inst1', 'ibmdb2');
$sth = $dbh->prepare("SELECT name, colour FROM fruit");
/* Подсчёт количества столбцов в (несуществующем) результирующем наборе */
$colcount = $sth->columnCount();
print("Перед вызовом execute(), в результирующем наборе $colcount столбцов (должно быть 0)\n");
$sth->execute();
/* Подсчёт количества столбцов в результирующем наборе */
$colcount = $sth->columnCount();
print("После вызова execute(), в результирующем наборе $colcount столбцов (должно быть 2)\n");
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
Перед вызовом execute(), в результирующем наборе 0 столбцов (должно быть 0)
После вызова execute(), в результирующем наборе 2 столбцов (должно быть 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
-->