<?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 => 'en',
  ),
  'this' => 
  array (
    0 => 'pdostatement.fetchcolumn.php',
    1 => 'PDOStatement::fetchColumn',
    2 => 'Returns a single column from the next row of a result set',
  ),
  'up' => 
  array (
    0 => 'class.pdostatement.php',
    1 => 'PDOStatement',
  ),
  'prev' => 
  array (
    0 => 'pdostatement.fetchall.php',
    1 => 'PDOStatement::fetchAll',
  ),
  'next' => 
  array (
    0 => 'pdostatement.fetchobject.php',
    1 => 'PDOStatement::fetchObject',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/pdo/pdostatement/fetchcolumn.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="pdostatement.fetchcolumn" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">PDOStatement::fetchColumn</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.1.0, PHP 7, PHP 8, PECL pdo &gt;= 0.9.0)</p><p class="refpurpose"><span class="refname">PDOStatement::fetchColumn</span> &mdash; <span class="dc-title">
   Returns a single column from the next row of a result set
  </span></p>

 </div>

 <div class="refsect1 description" id="refsect1-pdostatement.fetchcolumn-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>PDOStatement::fetchColumn</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$column</code><span class="initializer"> = 0</span></span>): <span class="type"><a href="language.types.mixed.php" class="type mixed">mixed</a></span></div>


  <p class="para rdfs-comment">
   Returns a single column from the next row of a result set or <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> if
   there are no more rows.
  </p>

  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    <span class="methodname"><strong>PDOStatement::fetchColumn()</strong></span> should not be used to
    retrieve boolean columns, as it is impossible to distinguish a value of
    <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> from there being no more rows to retrieve. Use
    <span class="methodname"><a href="pdostatement.fetch.php" class="methodname">PDOStatement::fetch()</a></span> instead.
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 parameters" id="refsect1-pdostatement.fetchcolumn-parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">column</code></dt>
     <dd>
      <p class="para">
       0-indexed number of the column you wish to retrieve from the row. If
       no value is supplied, <span class="methodname"><strong>PDOStatement::fetchColumn()</strong></span>
       fetches the first column.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-pdostatement.fetchcolumn-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   <span class="methodname"><strong>PDOStatement::fetchColumn()</strong></span> returns a single column
   from the next row of a result set or <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> if there are no more rows.
  </p>
  <div class="warning"><strong class="warning">Warning</strong>
   <p class="para">
    There is no way to return another column from the same row if you
    use <span class="methodname"><strong>PDOStatement::fetchColumn()</strong></span> to retrieve data.
   </p>
  </div>
 </div>


 <div class="refsect1 errors" id="refsect1-pdostatement.fetchcolumn-errors">
  <h3 class="title">Errors/Exceptions</h3>
  <p class="para">
Emits an error with level <strong><code><a href="errorfunc.constants.php#constant.e-warning">E_WARNING</a></code></strong> if the attribute <strong><code><a href="pdo.constants.php#pdo.constants.attr-errmode">PDO::ATTR_ERRMODE</a></code></strong> is set
to <strong><code><a href="pdo.constants.php#pdo.constants.errmode-warning">PDO::ERRMODE_WARNING</a></code></strong>.
</p>
<p class="para">
Throws a <span class="classname"><a href="class.pdoexception.php" class="classname">PDOException</a></span> if the attribute <strong><code><a href="pdo.constants.php#pdo.constants.attr-errmode">PDO::ATTR_ERRMODE</a></code></strong>
is set to <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.fetchcolumn-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="example-1"><p><strong>Example #1 Return first column of the next row</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$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 /></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 />print </span><span style="color: #DD0000">"Fetch the first column from the first row in the result set:\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$result </span><span style="color: #007700">= </span><span style="color: #0000BB">$sth</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">fetchColumn</span><span style="color: #007700">();<br />print </span><span style="color: #DD0000">"name = </span><span style="color: #0000BB">$result</span><span style="color: #DD0000">\n"</span><span style="color: #007700">;<br /><br />print </span><span style="color: #DD0000">"Fetch the second column from the second row in the result set:\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$result </span><span style="color: #007700">= </span><span style="color: #0000BB">$sth</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">fetchColumn</span><span style="color: #007700">(</span><span style="color: #0000BB">1</span><span style="color: #007700">);<br />print </span><span style="color: #DD0000">"colour = </span><span style="color: #0000BB">$result</span><span style="color: #DD0000">\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>The above example will output:</p></div>
    <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">Fetch the first column from the first row in the result set:
name = lemon
Fetch the second column from the second row in the result set:
colour = red</pre>
</div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-pdostatement.fetchcolumn-seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="methodname"><a href="pdo.query.php" class="methodname" rel="rdfs-seeAlso">PDO::query()</a> - Prepares and executes an SQL statement without placeholders</span></li>
    <li><span class="methodname"><a href="pdostatement.fetch.php" class="methodname" rel="rdfs-seeAlso">PDOStatement::fetch()</a> - Fetches the next row from a result set</span></li>
    <li><span class="methodname"><a href="pdostatement.fetchall.php" class="methodname" rel="rdfs-seeAlso">PDOStatement::fetchAll()</a> - Fetches the remaining rows from a result set</span></li>
    <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.setfetchmode.php" class="methodname" rel="rdfs-seeAlso">PDOStatement::setFetchMode()</a> - Set the default fetch mode for this statement</span></li>
   </ul>
  </p>
 </div>

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