downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

Our source is open

The syntax highlighted source is automatically generated by PHP from the plaintext script. If you're interested in what's behind the several functions we used, you can always take a look at the source of the following files:

Of course, if you want to see the source of this page, we have it available. You can also browse the SVN repository for this website on svn.php.net.

Source of: /manual/en/pdostatement.fetchcolumn.php

<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = 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',
  ),
 
'up' =>
  array (
   
0 => 'class.pdostatement.php',
   
1 => 'The PDOStatement class',
  ),
 
'prev' =>
  array (
   
0 => 'pdostatement.fetchall.php',
   
1 => 'PDOStatement->fetchAll',
  ),
 
'next' =>
  array (
   
0 => 'pdostatement.fetchobject.php',
   
1 => 'PDOStatement->fetchObject',
  ),
);
$setup["toc"] = $TOC;
$setup["parents"] = $PARENTS;
manual_setup($setup);

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

 </div>

 <a name="pdostatement.fetchcolumn.description"></a><div class="refsect1 description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">string</span> <span class="methodname"><b>PDOStatement::fetchColumn</b></span>
    ([ <span class="methodparam"><span class="type">int</span> <tt class="parameter">$column_number</tt><span class="initializer"> = 0</span></span>
  ] )</div>


  <p class="para rdfs-comment">
   Returns a single column from the next row of a result set or <b><tt class="constant">FALSE</tt></b> if
   there are no more rows.
  </p>
 </div>


 <a name="pdostatement.fetchcolumn.parameters"></a><div class="refsect1 parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   </p><dl>

    <dt class="varlistentry">

     <span class="term"><i><tt class="parameter">column_number</tt></i>
</span>

     </dt><dd class="listitem">

      <p class="para">
       0-indexed number of the column you wish to retrieve from the row. If
       no value is supplied, <b>PDOStatement::fetchColumn()</b>
       fetches the first column.
      </p>
     </dd>

   
   </dl>
<p>
  </p>
 </div>


 <a name="pdostatement.fetchcolumn.returnvalues"></a><div class="refsect1 returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   <b>PDOStatement::fetchColumn()</b> returns a single column
   in the next row of a result set.
  </p>
  <div class="warning"><b class="warning">Warning</b>
   <p class="para">
    There is no way to return another column from the same row if you
    use <b>PDOStatement::fetchColumn()</b> to retrieve data.
   </p>
  </div>
 </div>


 <a name="pdostatement.fetchcolumn.examples"></a><div class="refsect1 examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   </p><div class="example"><p><b>Example #1 Return first column of the next row</b></p>
    <div class="example-contents programlisting">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$sth&nbsp;</span><span style="color: #007700">=&nbsp;</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&nbsp;name,&nbsp;colour&nbsp;FROM&nbsp;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 /></span><span style="color: #FF8000">/*&nbsp;Fetch&nbsp;the&nbsp;first&nbsp;column&nbsp;from&nbsp;the&nbsp;next&nbsp;row&nbsp;in&nbsp;the&nbsp;result&nbsp;set&nbsp;*/<br /></span><span style="color: #007700">print(</span><span style="color: #DD0000">"Fetch&nbsp;the&nbsp;first&nbsp;column&nbsp;from&nbsp;the&nbsp;next&nbsp;row&nbsp;in&nbsp;the&nbsp;result&nbsp;set:\n"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$result&nbsp;</span><span style="color: #007700">=&nbsp;</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&nbsp;=&nbsp;</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&nbsp;the&nbsp;second&nbsp;column&nbsp;from&nbsp;the&nbsp;next&nbsp;row&nbsp;in&nbsp;the&nbsp;result&nbsp;set:\n"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$result&nbsp;</span><span style="color: #007700">=&nbsp;</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&nbsp;=&nbsp;</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 para"><p>The above example will output:</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
Fetch the first column from the next row in the result set:
name = lemon
Fetch the second column from the next row in the result set:
colour = red
</pre></div>
    </div>
   </div><p>
  </p>
 </div>


 <a name="pdostatement.fetchcolumn.seealso"></a><div class="refsect1 seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   </p><ul class="simplelist">
    <li class="member"><a href="pdo.query.php" class="function" rel="rdfs-seeAlso">PDO::query()</a> - Executes an SQL statement, returning a result set as a PDOStatement object</li>
    <li class="member"><a href="pdostatement.fetch.php" class="function" rel="rdfs-seeAlso">PDOStatement::fetch()</a> - Fetches the next row from a result set</li>
    <li class="member"><a href="pdostatement.fetchall.php" class="function" rel="rdfs-seeAlso">PDOStatement::fetchAll()</a> - Returns an array containing all of the result set rows</li>
    <li class="member"><a href="pdo.prepare.php" class="function" rel="rdfs-seeAlso">PDO::prepare()</a> - Prepares a statement for execution and returns a statement object</li>
    <li class="member"><a href="pdostatement.setfetchmode.php" class="function" rel="rdfs-seeAlso">PDOStatement::setFetchMode()</a> - Set the default fetch mode for this statement</li>
   </ul><p>
  </p>
 </div>

</div><?php manual_footer(); ?>
 
show source | credits | sitemap | contact | advertising | mirror sites