<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/class.pdostatement.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'uk',
  ),
  'this' => 
  array (
    0 => 'pdostatement.columncount.php',
    1 => 'PDOStatement::columnCount',
    2 => 'Returns the number of columns in the result set',
  ),
  'up' => 
  array (
    0 => 'class.pdostatement.php',
    1 => 'PDOStatement',
  ),
  'prev' => 
  array (
    0 => 'pdostatement.closecursor.php',
    1 => 'PDOStatement::closeCursor',
  ),
  'next' => 
  array (
    0 => 'pdostatement.debugdumpparams.php',
    1 => 'PDOStatement::debugDumpParams',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/pdo/pdostatement/columncount.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="pdostatement.columncount" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">PDOStatement::columnCount</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.1.0, PHP 7, PHP 8, PECL pdo &gt;= 0.2.0)</p><p class="refpurpose"><span class="refname">PDOStatement::columnCount</span> &mdash; <span class="dc-title">
   Returns the number of columns in the result set
  </span></p>

 </div>
 <div class="refsect1 description" id="refsect1-pdostatement.columncount-description">
  <h3 class="title">Опис</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>PDOStatement::columnCount</strong></span>(): <span class="type"><a href="language.types.integer.php" class="type int">int</a></span></div>


  <p class="para rdfs-comment">
   Use <span class="methodname"><strong>PDOStatement::columnCount()</strong></span> to return the number
   of columns in the result set represented by the PDOStatement object.
  </p>
  <p class="para">
   If the PDOStatement object was returned from <span class="methodname"><a href="pdo.query.php" class="methodname">PDO::query()</a></span>,
   the column count is immediately available.
  </p>
  <p class="para">
   If the PDOStatement object was returned from
   <span class="methodname"><a href="pdo.prepare.php" class="methodname">PDO::prepare()</a></span>, an accurate column count will not be
   available until you invoke <span class="methodname"><a href="pdostatement.execute.php" class="methodname">PDOStatement::execute()</a></span>.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-pdostatement.columncount-parameters">
  <h3 class="title">Параметри</h3>
  <p class="para">У цієї функції немає
параметрів.</p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-pdostatement.columncount-returnvalues">
  <h3 class="title">Значення, що повертаються</h3>
  <p class="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,
   <span class="methodname"><strong>PDOStatement::columnCount()</strong></span> returns <code class="literal">0</code>.
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-pdostatement.columncount-errors">
  <h3 class="title">Помилки/виключення</h3>
  <p class="para">
Видає помилку рівня <strong><code><a href="errorfunc.constants.php#constant.e-warning">E_WARNING</a></code></strong>, якщо атрибут
<strong><code><a href="pdo.constants.php#pdo.constants.attr-errmode">PDO::ATTR_ERRMODE</a></code></strong> дорівнює
<strong><code><a href="pdo.constants.php#pdo.constants.errmode-warning">PDO::ERRMODE_WARNING</a></code></strong>.
</p>
<p class="para">
Викидає <span class="classname"><a href="class.pdoexception.php" class="classname">PDOException</a></span>, якщо атрибут
<strong><code><a href="pdo.constants.php#pdo.constants.attr-errmode">PDO::ATTR_ERRMODE</a></code></strong> дорівнює
<strong><code><a href="pdo.constants.php#pdo.constants.errmode-exception">PDO::ERRMODE_EXCEPTION</a></code></strong>.
</p>
 </div>


 <div class="refsect1 examples" id="refsect1-pdostatement.columncount-examples">
  <h3 class="title">Приклади</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Приклад #1 Counting columns</strong></p>
    <div class="example-contents"><p>
     This example demonstrates how <span class="methodname"><strong>PDOStatement::columnCount()</strong></span>
     operates with and without a result set.
    </p></div>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$dbh </span><span style="color: #007700">= new </span><span style="color: #0000BB">PDO</span><span style="color: #007700">(</span><span style="color: #DD0000">'odbc:sample'</span><span style="color: #007700">, </span><span style="color: #DD0000">'db2inst1'</span><span style="color: #007700">, </span><span style="color: #DD0000">'ibmdb2'</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$sth </span><span style="color: #007700">= </span><span style="color: #0000BB">$dbh</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">prepare</span><span style="color: #007700">(</span><span style="color: #DD0000">"SELECT name, colour FROM fruit"</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/* Count the number of columns in the (non-existent) result set */<br /></span><span style="color: #0000BB">$colcount </span><span style="color: #007700">= </span><span style="color: #0000BB">$sth</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">columnCount</span><span style="color: #007700">();<br />print </span><span style="color: #DD0000">"Before execute(), result set has </span><span style="color: #0000BB">$colcount</span><span style="color: #DD0000"> columns (should be 0)\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$sth</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">execute</span><span style="color: #007700">();<br /><br /></span><span style="color: #FF8000">/* Count the number of columns in the result set */<br /></span><span style="color: #0000BB">$colcount </span><span style="color: #007700">= </span><span style="color: #0000BB">$sth</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">columnCount</span><span style="color: #007700">();<br />print </span><span style="color: #DD0000">"After execute(), result set has </span><span style="color: #0000BB">$colcount</span><span style="color: #DD0000"> columns (should be 2)\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>Поданий вище приклад
виведе:</p></div>
    <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">Before execute(), result set has 0 columns (should be 0)
After execute(), result set has 2 columns (should be 2)</pre>
</div>
    </div>
   </div>
  </p>
 </div>



 <div class="refsect1 seealso" id="refsect1-pdostatement.columncount-seealso">
  <h3 class="title">Прогляньте також</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="methodname"><a href="pdo.prepare.php" class="methodname" rel="rdfs-seeAlso">PDO::prepare()</a> - Prepares a statement for execution and returns a statement object</span></li>
    <li><span class="methodname"><a href="pdostatement.execute.php" class="methodname" rel="rdfs-seeAlso">PDOStatement::execute()</a> - Executes a prepared statement</span></li>
    <li><span class="methodname"><a href="pdostatement.rowcount.php" class="methodname" rel="rdfs-seeAlso">PDOStatement::rowCount()</a> - Returns the number of rows affected by the last SQL statement</span></li>
   </ul>
  </p>
 </div>


</div><?php manual_footer($setup); ?>