downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | 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 Git repository for this website on git.php.net.

Source of: /manual/en/function.db2-fetch-both.php

<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$PARENTS = array();
include_once
dirname(__FILE__) ."/toc/ref.ibm-db2.inc";
$setup = array (
 
'home' =>
  array (
   
0 => 'index.php',
   
1 => 'PHP Manual',
  ),
 
'head' =>
  array (
   
0 => 'UTF-8',
   
1 => 'en',
  ),
 
'this' =>
  array (
   
0 => 'function.db2-fetch-both.php',
   
1 => 'db2_fetch_both',
  ),
 
'up' =>
  array (
   
0 => 'ref.ibm-db2.php',
   
1 => 'IBM DB2 Functions',
  ),
 
'prev' =>
  array (
   
0 => 'function.db2-fetch-assoc.php',
   
1 => 'db2_fetch_assoc',
  ),
 
'next' =>
  array (
   
0 => 'function.db2-fetch-object.php',
   
1 => 'db2_fetch_object',
  ),
 
'alternatives' =>
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["parents"] = $PARENTS;
manual_setup($setup);

manual_header();
?>
<div id="function.db2-fetch-both" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">db2_fetch_both</h1>
  <p class="verinfo">(PECL ibm_db2 &gt;= 1.0.0)</p><p class="refpurpose"><span class="refname">db2_fetch_both</span> &mdash; <span class="dc-title">
   Returns an array, indexed by both column name and position, representing a row in a result set
  </span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.db2-fetch-both-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">array</span> <span class="methodname"><strong>db2_fetch_both</strong></span>
    ( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$stmt</code></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$row_number</code><span class="initializer"> = -1</span></span>
  ] )</div>



  <p class="para rdfs-comment">
   Returns an array, indexed by both column name and position, representing a
   row in a result set. Note that the row returned by
    <span class="function"><strong>db2_fetch_both()</strong></span> requires more memory than the
   single-indexed arrays returned by  <span class="function"><a href="function.db2-fetch-assoc.php" class="function">db2_fetch_assoc()</a></span> or
    <span class="function"><a href="function.db2-fetch-array.php" class="function">db2_fetch_array()</a></span>.
  </p>

 </div>

 <div class="refsect1 parameters" id="refsect1-function.db2-fetch-both-parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   <dl>

    <dt>

     <span class="term"><em><code class="parameter">stmt</code></em></span>
     <dd>

      <p class="para">
       A valid <em>stmt</em> resource containing a result set.
      </p>
     </dd>

    </dt>

    <dt>

     <span class="term"><em><code class="parameter">row_number</code></em></span>
     <dd>

      <p class="para">
       Requests a specific 1-indexed row from the result set. Passing this
       parameter results in a PHP warning if the result set uses a
       forward-only cursor.
      </p>
     </dd>

    </dt>

   </dl>

  </p>
 </div>

 <div class="refsect1 returnvalues" id="refsect1-function.db2-fetch-both-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   Returns an associative array with column values indexed by both the column
   name and 0-indexed column number. The array represents the next or
   requested row in the result set. Returns <strong><code>FALSE</code></strong> if there are no rows left
   in the result set, or if the row requested by
   <em><code class="parameter">row_number</code></em> does not exist in the result set.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.db2-fetch-both-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="example-1232">
    <p><strong>Example #1 Iterating through a forward-only cursor</strong></p>
    <div class="example-contents"><p>
     If you call  <span class="function"><strong>db2_fetch_both()</strong></span> without a specific row
     number, it automatically retrieves the next row in the result set. The
     following example accesses columns in the returned array by both column
     name and by numeric index.
    </p></div>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />$sql&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"SELECT&nbsp;id,&nbsp;name,&nbsp;breed,&nbsp;weight&nbsp;FROM&nbsp;animals&nbsp;ORDER&nbsp;BY&nbsp;breed"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$stmt&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">db2_prepare</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$sql</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$result&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">db2_execute</span><span style="color: #007700">(</span><span style="color: #0000BB">$stmt</span><span style="color: #007700">);<br /><br />while&nbsp;(</span><span style="color: #0000BB">$row&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">db2_fetch_both</span><span style="color: #007700">(</span><span style="color: #0000BB">$stmt</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">printf&nbsp;</span><span style="color: #007700">(</span><span style="color: #DD0000">"%-5d&nbsp;%-16s&nbsp;%-32s&nbsp;%10s\n"</span><span style="color: #007700">,&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #DD0000">'ID'</span><span style="color: #007700">],&nbsp;</span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #0000BB">0</span><span style="color: #007700">],&nbsp;</span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #DD0000">'BREED'</span><span style="color: #007700">],&nbsp;</span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #0000BB">3</span><span style="color: #007700">]);<br />}<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="cdata"><pre>
0     Pook             cat                                    3.20
5     Rickety Ride     goat                                   9.70
2     Smarty           horse                                350.00
</pre></div>
    </div>
   </div>

   <div class="example" id="example-1233">
    <p><strong>Example #2 Retrieving specific rows with  <span class="function"><strong>db2_fetch_both()</strong></span>
     from a scrollable cursor</strong></p>
    <div class="example-contents"><p>
     If your result set uses a scrollable cursor, you can call
      <span class="function"><strong>db2_fetch_both()</strong></span> with a specific row number. The
     following example retrieves every other row in the result set, starting
     with the second row.
    </p></div>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />$sql&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"SELECT&nbsp;id,&nbsp;name,&nbsp;breed,&nbsp;weight&nbsp;FROM&nbsp;animals&nbsp;ORDER&nbsp;BY&nbsp;breed"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$result&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">db2_exec</span><span style="color: #007700">(</span><span style="color: #0000BB">$stmt</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$sql</span><span style="color: #007700">,&nbsp;array(</span><span style="color: #DD0000">'cursor'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">DB2_SCROLLABLE</span><span style="color: #007700">));<br /><br /></span><span style="color: #0000BB">$i</span><span style="color: #007700">=</span><span style="color: #0000BB">2</span><span style="color: #007700">;<br />while&nbsp;(</span><span style="color: #0000BB">$row&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">db2_fetch_both</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$i</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">printf&nbsp;</span><span style="color: #007700">(</span><span style="color: #DD0000">"%-5d&nbsp;%-16s&nbsp;%-32s&nbsp;%10s\n"</span><span style="color: #007700">,&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #0000BB">0</span><span style="color: #007700">],&nbsp;</span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #DD0000">'NAME'</span><span style="color: #007700">],&nbsp;</span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #0000BB">2</span><span style="color: #007700">],&nbsp;</span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #DD0000">'WEIGHT'</span><span style="color: #007700">]);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$i&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$i&nbsp;</span><span style="color: #007700">+&nbsp;</span><span style="color: #0000BB">2</span><span style="color: #007700">;<br />}<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="cdata"><pre>
0     Pook             cat                                    3.20
5     Rickety Ride     goat                                   9.70
2     Smarty           horse                                350.00
</pre></div>
    </div>
   </div>
  </p>
 </div>



 <div class="refsect1 seealso" id="refsect1-function.db2-fetch-both-seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"> <span class="function"><a href="function.db2-fetch-array.php" class="function" rel="rdfs-seeAlso">db2_fetch_array()</a> - Returns an array, indexed by column position, representing a row in a result set</span></li>
    <li class="member"> <span class="function"><a href="function.db2-fetch-assoc.php" class="function" rel="rdfs-seeAlso">db2_fetch_assoc()</a> - Returns an array, indexed by column name, representing a row in a result set</span></li>
    <li class="member"> <span class="function"><a href="function.db2-fetch-object.php" class="function" rel="rdfs-seeAlso">db2_fetch_object()</a> - Returns an object with properties representing columns in the fetched row</span></li>
    <li class="member"> <span class="function"><a href="function.db2-fetch-row.php" class="function" rel="rdfs-seeAlso">db2_fetch_row()</a> - Sets the result set pointer to the next row or requested row</span></li>
    <li class="member"> <span class="function"><a href="function.db2-result.php" class="function" rel="rdfs-seeAlso">db2_result()</a> - Returns a single column from a row in the result set</span></li>
   </ul>
  </p>
 </div>



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