<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = 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 => 'zh',
  ),
  'this' => 
  array (
    0 => 'function.db2-fetch-object.php',
    1 => 'db2_fetch_object',
    2 => 'Returns an object with properties representing columns in the fetched row',
  ),
  'up' => 
  array (
    0 => 'ref.ibm-db2.php',
    1 => 'IBM DB2 函数',
  ),
  'prev' => 
  array (
    0 => 'function.db2-fetch-both.php',
    1 => 'db2_fetch_both',
  ),
  'next' => 
  array (
    0 => 'function.db2-fetch-row.php',
    1 => 'db2_fetch_row',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/ibm_db2/functions/db2-fetch-object.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.db2-fetch-object" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">db2_fetch_object</h1>
  <p class="verinfo">(PECL ibm_db2 &gt;= 1.0.0)</p><p class="refpurpose"><span class="refname">db2_fetch_object</span> &mdash; <span class="dc-title">
   Returns an object with properties representing columns in the fetched row
  </span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.db2-fetch-object-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>db2_fetch_object</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.resource.php" class="type resource">resource</a></span> <code class="parameter">$stmt</code></span>, <span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$row_number</code><span class="initializer"> = -1</span></span>): <span class="type"><span class="type"><a href="class.stdclass.php" class="type stdClass">stdClass</a></span>|<span class="type"><a href="language.types.singleton.php" class="type false">false</a></span></span></div>



  <p class="simpara">
   Returns an object in which each property represents a column returned in
   the row fetched from a result set.
  </p>

 </div>

 <div class="refsect1 parameters" id="refsect1-function.db2-fetch-object-parameters">
  <h3 class="title">参数</h3>
  <dl>
   
    <dt><code class="parameter">stmt</code></dt>
    <dd>
     <span class="simpara">
      A valid <code class="literal">stmt</code> resource containing a result set.
     </span>
    </dd>
   
   
    <dt><code class="parameter">row_number</code></dt>
    <dd>
     <span class="simpara">
      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.
     </span>
    </dd>
   
  </dl>
 </div>

 <div class="refsect1 returnvalues" id="refsect1-function.db2-fetch-object-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="simpara">
   Returns an object representing a single row in the result set. The
   properties of the object map to the names of the columns in the result set.
  </p>
  <p class="simpara">
   The IBM DB2, Cloudscape, and Apache Derby database servers typically fold
   column names to upper-case, so the object properties will reflect that case.
  </p>
  <p class="simpara">
   If your SELECT statement calls a scalar function to modify the value
   of a column, the database servers return the column number as the name of
   the column in the result set. If you prefer a more descriptive column name
   and object property, you can use the AS clause to assign a name to the
   column in the result set.
  </p>
  <p class="simpara">
   Returns <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> if no row was retrieved.
  </p>
 </div>


<div class="refsect1 examples" id="refsect1-function.db2-fetch-object-examples">
  <h3 class="title">示例</h3>
  <div class="example" id="example-1">
   <p><strong>示例 #1 A <span class="function"><strong>db2_fetch_object()</strong></span> example</strong></p>
   <div class="example-contents"><p>
    The following example issues a SELECT statement with a scalar function,
    RTRIM, that removes whitespace from the end of the column. Rather than
    creating an object with the properties &quot;BREED&quot; and &quot;2&quot;, we use the AS
    clause in the SELECT statement to assign the name &quot;name&quot; to the modified
    column. The database server folds the column names to upper-case,
    resulting in an object with the properties &quot;BREED&quot; and &quot;NAME&quot;.
   </p></div>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$conn </span><span style="color: #007700">= </span><span style="color: #0000BB">db2_connect</span><span style="color: #007700">(</span><span style="color: #0000BB">$database</span><span style="color: #007700">, </span><span style="color: #0000BB">$user</span><span style="color: #007700">, </span><span style="color: #0000BB">$password</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$sql </span><span style="color: #007700">= </span><span style="color: #DD0000">"SELECT breed, RTRIM(name) AS name<br />    FROM animals<br />    WHERE id = ?"</span><span style="color: #007700">;<br /><br />if (</span><span style="color: #0000BB">$conn</span><span style="color: #007700">) {<br />    </span><span style="color: #0000BB">$stmt </span><span style="color: #007700">= </span><span style="color: #0000BB">db2_prepare</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">, </span><span style="color: #0000BB">$sql</span><span style="color: #007700">);<br />    </span><span style="color: #0000BB">db2_execute</span><span style="color: #007700">(</span><span style="color: #0000BB">$stmt</span><span style="color: #007700">, array(</span><span style="color: #0000BB">0</span><span style="color: #007700">));<br /><br />    while (</span><span style="color: #0000BB">$pet </span><span style="color: #007700">= </span><span style="color: #0000BB">db2_fetch_object</span><span style="color: #007700">(</span><span style="color: #0000BB">$stmt</span><span style="color: #007700">)) {<br />        echo </span><span style="color: #DD0000">"Come here, </span><span style="color: #007700">{</span><span style="color: #0000BB">$pet</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">NAME</span><span style="color: #007700">}</span><span style="color: #DD0000">, my little </span><span style="color: #007700">{</span><span style="color: #0000BB">$pet</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">BREED</span><span style="color: #007700">}</span><span style="color: #DD0000">!"</span><span style="color: #007700">;<br />    }<br />    </span><span style="color: #0000BB">db2_close</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</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">Come here, Pook, my little cat!</pre>
</div>
   </div>
  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.db2-fetch-object-seealso">
  <h3 class="title">参见</h3>
  <ul class="simplelist">
   <li><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><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><span class="function"><a href="function.db2-fetch-both.php" class="function" rel="rdfs-seeAlso">db2_fetch_both()</a> - Returns an array, indexed by both column name and position, representing a row in a result set</span></li>
   <li><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><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>
 </div>



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