<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.oci8.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'it',
  ),
  'this' => 
  array (
    0 => 'function.oci-fetch-object.php',
    1 => 'oci_fetch_object',
    2 => 'Returns the next row from a query as an object',
  ),
  'up' => 
  array (
    0 => 'ref.oci8.php',
    1 => 'OCI8 Funzioni',
  ),
  'prev' => 
  array (
    0 => 'function.oci-fetch-assoc.php',
    1 => 'oci_fetch_assoc',
  ),
  'next' => 
  array (
    0 => 'function.oci-fetch-row.php',
    1 => 'oci_fetch_row',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/oci8/functions/oci-fetch-object.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.oci-fetch-object" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">oci_fetch_object</h1>
  <p class="verinfo">(PHP 5, PHP 7, PHP 8, PECL OCI8 &gt;= 1.1.0)</p><p class="refpurpose"><span class="refname">oci_fetch_object</span> &mdash; <span class="dc-title">Returns the next row from a query as an object</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.oci-fetch-object-description">
  <h3 class="title">Descrizione</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>oci_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">$statement</code></span>, <span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$mode</code><span class="initializer"> = OCI_ASSOC | OCI_RETURN_NULLS</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="para rdfs-comment">
   Returns an object containing the next result-set row of a query.
   Each attribute of the object corresponds to a column of the row.
   This function is typically called in a loop until it returns
   <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>, indicating no more rows exist.
  </p>
  <p class="para">Per dettagli sul mappaggio dei tipi dati effettuato dal
driver OCI8, vedere i <a href="oci8.datatypes.php" class="link">tipi di dato
supportati dal driver</a></p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.oci-fetch-object-parameters">
  <h3 class="title">Elenco dei parametri</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">statement</code></dt>
     <dd>
       <p class="para">Un identificativo valido di
statement OCI8 creato da <span class="function"><a href="function.oci-parse.php" class="function">oci_parse()</a></span> e eseguito
da <span class="function"><a href="function.oci-execute.php" class="function">oci_execute()</a></span>, o un identificativo di statement <code class="literal">REF
CURSOR</code>.</p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.oci-fetch-object-returnvalues">
  <h3 class="title">Valori restituiti</h3>
  <p class="para">
   Returns an object.  Each attribute of the object corresponds to a
   column of the row.  If there are no more rows in
   the <code class="parameter">statement</code> then <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> is returned.
  </p>
  <p class="para">
    Any <code class="literal">LOB</code> columns are returned as LOB descriptors.
  </p>
  <p class="para">
   <code class="literal">DATE</code> columns are returned as strings formatted
   to the current date format.  The default format can be changed with
   Oracle environment variables such as <code class="literal">NLS_LANG</code> or
   by a previously executed <code class="literal">ALTER SESSION SET
   NLS_DATE_FORMAT</code> command.
  </p>
  <p class="para">
   Oracle&#039;s default, non-case sensitive column names will have
   uppercase attribute names.  Case-sensitive column names will have
   attribute names using the exact column case.
   Use <span class="function"><a href="function.var-dump.php" class="function">var_dump()</a></span> on the result object to verify
   the appropriate case for attribute access.
  </p>
  <p class="para">
    Attribute values will be <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong> for any <code class="literal">NULL</code>
    data fields.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.oci-fetch-object-examples">
  <h3 class="title">Esempi</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Example #1 <span class="function"><strong>oci_fetch_object()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #FF8000">/*<br />  Before running, create the table:<br />    CREATE TABLE mytab (id NUMBER, description VARCHAR2(30));<br />    INSERT INTO mytab (id, description) values (1, 'Fish and Chips');<br />    COMMIT;<br />*/<br /><br /></span><span style="color: #0000BB">$conn </span><span style="color: #007700">= </span><span style="color: #0000BB">oci_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">'hr'</span><span style="color: #007700">, </span><span style="color: #DD0000">'welcome'</span><span style="color: #007700">, </span><span style="color: #DD0000">'localhost/XE'</span><span style="color: #007700">);<br />if (!</span><span style="color: #0000BB">$conn</span><span style="color: #007700">) {<br />    </span><span style="color: #0000BB">$e </span><span style="color: #007700">= </span><span style="color: #0000BB">oci_error</span><span style="color: #007700">();<br />    </span><span style="color: #0000BB">trigger_error</span><span style="color: #007700">(</span><span style="color: #0000BB">htmlentities</span><span style="color: #007700">(</span><span style="color: #0000BB">$e</span><span style="color: #007700">[</span><span style="color: #DD0000">'message'</span><span style="color: #007700">], </span><span style="color: #0000BB">ENT_QUOTES</span><span style="color: #007700">), </span><span style="color: #0000BB">E_USER_ERROR</span><span style="color: #007700">);<br />}<br /><br /></span><span style="color: #0000BB">$stid </span><span style="color: #007700">= </span><span style="color: #0000BB">oci_parse</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">, </span><span style="color: #DD0000">'SELECT id, description FROM mytab'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">oci_execute</span><span style="color: #007700">(</span><span style="color: #0000BB">$stid</span><span style="color: #007700">);<br /><br />while ((</span><span style="color: #0000BB">$row </span><span style="color: #007700">= </span><span style="color: #0000BB">oci_fetch_object</span><span style="color: #007700">(</span><span style="color: #0000BB">$stid</span><span style="color: #007700">)) != </span><span style="color: #0000BB">false</span><span style="color: #007700">) {<br />    </span><span style="color: #FF8000">// Use upper case attribute names for each standard Oracle column<br />    </span><span style="color: #007700">echo </span><span style="color: #0000BB">$row</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">ID </span><span style="color: #007700">. </span><span style="color: #DD0000">"&lt;br&gt;\n"</span><span style="color: #007700">;<br />    echo </span><span style="color: #0000BB">$row</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">DESCRIPTION </span><span style="color: #007700">. </span><span style="color: #DD0000">"&lt;br&gt;\n"</span><span style="color: #007700">; <br />}<br /><br /></span><span style="color: #FF8000">// Output is:<br />//    1<br />//    Fish and Chips<br /><br /></span><span style="color: #0000BB">oci_free_statement</span><span style="color: #007700">(</span><span style="color: #0000BB">$stid</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">oci_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>
  </p>
  <p class="para">
   <div class="example" id="example-2">
    <p><strong>Example #2 <span class="function"><strong>oci_fetch_object()</strong></span> with case sensitive column names</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #FF8000">/*<br />  Before running, create the table with a case sensitive column name:<br />    CREATE TABLE mytab (id NUMBER, "MyDescription" VARCHAR2(30));<br />    INSERT INTO mytab (id, "MyDescription") values (1, 'Iced Coffee');<br />    COMMIT;<br />*/<br /><br /></span><span style="color: #0000BB">$conn </span><span style="color: #007700">= </span><span style="color: #0000BB">oci_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">'hr'</span><span style="color: #007700">, </span><span style="color: #DD0000">'welcome'</span><span style="color: #007700">, </span><span style="color: #DD0000">'localhost/XE'</span><span style="color: #007700">);<br />if (!</span><span style="color: #0000BB">$conn</span><span style="color: #007700">) {<br />    </span><span style="color: #0000BB">$e </span><span style="color: #007700">= </span><span style="color: #0000BB">oci_error</span><span style="color: #007700">();<br />    </span><span style="color: #0000BB">trigger_error</span><span style="color: #007700">(</span><span style="color: #0000BB">htmlentities</span><span style="color: #007700">(</span><span style="color: #0000BB">$e</span><span style="color: #007700">[</span><span style="color: #DD0000">'message'</span><span style="color: #007700">], </span><span style="color: #0000BB">ENT_QUOTES</span><span style="color: #007700">), </span><span style="color: #0000BB">E_USER_ERROR</span><span style="color: #007700">);<br />}<br /><br /></span><span style="color: #0000BB">$stid </span><span style="color: #007700">= </span><span style="color: #0000BB">oci_parse</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">, </span><span style="color: #DD0000">'SELECT id, "MyDescription" FROM mytab'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">oci_execute</span><span style="color: #007700">(</span><span style="color: #0000BB">$stid</span><span style="color: #007700">);<br /><br />while ((</span><span style="color: #0000BB">$row </span><span style="color: #007700">= </span><span style="color: #0000BB">oci_fetch_object</span><span style="color: #007700">(</span><span style="color: #0000BB">$stid</span><span style="color: #007700">)) != </span><span style="color: #0000BB">false</span><span style="color: #007700">) {<br />    </span><span style="color: #FF8000">// Use upper case attribute names for each standard Oracle column<br />    </span><span style="color: #007700">echo </span><span style="color: #0000BB">$row</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">ID </span><span style="color: #007700">. </span><span style="color: #DD0000">"&lt;br&gt;\n"</span><span style="color: #007700">;<br />    </span><span style="color: #FF8000">// Use the exact case for the case sensitive column name<br />    </span><span style="color: #007700">echo </span><span style="color: #0000BB">$row</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">MyDescription </span><span style="color: #007700">. </span><span style="color: #DD0000">"&lt;br&gt;\n"</span><span style="color: #007700">;   <br />}<br /><br /></span><span style="color: #FF8000">// Output is:<br />//    1<br />//    Iced Coffee<br /><br /></span><span style="color: #0000BB">oci_free_statement</span><span style="color: #007700">(</span><span style="color: #0000BB">$stid</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">oci_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>
  </p>
  <p class="para">
   <div class="example" id="example-3">
    <p><strong>Example #3 <span class="function"><strong>oci_fetch_object()</strong></span> with LOBs</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #FF8000">/*<br />  Before running, create the table:<br />    CREATE TABLE mytab (id NUMBER, description CLOB);<br />    INSERT INTO mytab (id, description) values (1, 'A very long string');<br />    COMMIT;<br />*/<br /><br /></span><span style="color: #0000BB">$conn </span><span style="color: #007700">= </span><span style="color: #0000BB">oci_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">'hr'</span><span style="color: #007700">, </span><span style="color: #DD0000">'welcome'</span><span style="color: #007700">, </span><span style="color: #DD0000">'localhost/XE'</span><span style="color: #007700">);<br />if (!</span><span style="color: #0000BB">$conn</span><span style="color: #007700">) {<br />    </span><span style="color: #0000BB">$e </span><span style="color: #007700">= </span><span style="color: #0000BB">oci_error</span><span style="color: #007700">();<br />    </span><span style="color: #0000BB">trigger_error</span><span style="color: #007700">(</span><span style="color: #0000BB">htmlentities</span><span style="color: #007700">(</span><span style="color: #0000BB">$e</span><span style="color: #007700">[</span><span style="color: #DD0000">'message'</span><span style="color: #007700">], </span><span style="color: #0000BB">ENT_QUOTES</span><span style="color: #007700">), </span><span style="color: #0000BB">E_USER_ERROR</span><span style="color: #007700">);<br />}<br /><br /></span><span style="color: #0000BB">$stid </span><span style="color: #007700">= </span><span style="color: #0000BB">oci_parse</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">, </span><span style="color: #DD0000">'SELECT id, description FROM mytab'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">oci_execute</span><span style="color: #007700">(</span><span style="color: #0000BB">$stid</span><span style="color: #007700">);<br /><br />while ((</span><span style="color: #0000BB">$row </span><span style="color: #007700">= </span><span style="color: #0000BB">oci_fetch_object</span><span style="color: #007700">(</span><span style="color: #0000BB">$stid</span><span style="color: #007700">)) != </span><span style="color: #0000BB">false</span><span style="color: #007700">) {<br />    echo </span><span style="color: #0000BB">$row</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">ID </span><span style="color: #007700">. </span><span style="color: #DD0000">"&lt;br&gt;\n"</span><span style="color: #007700">;<br />    </span><span style="color: #FF8000">// The following will output the first 11 bytes from DESCRIPTION<br />    </span><span style="color: #007700">echo </span><span style="color: #0000BB">$row</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">DESCRIPTION</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">read</span><span style="color: #007700">(</span><span style="color: #0000BB">11</span><span style="color: #007700">) . </span><span style="color: #DD0000">"&lt;br&gt;\n"</span><span style="color: #007700">; <br />}<br /><br /></span><span style="color: #FF8000">// Output is:<br />//    1<br />//    A very long<br /><br /></span><span style="color: #0000BB">oci_free_statement</span><span style="color: #007700">(</span><span style="color: #0000BB">$stid</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">oci_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>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.oci-fetch-object-seealso">
  <h3 class="title">Vedere anche:</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.oci-fetch.php" class="function" rel="rdfs-seeAlso">oci_fetch()</a> - Fetches the next row from a query into internal buffers</span></li>
    <li><span class="function"><a href="function.oci-fetch-all.php" class="function" rel="rdfs-seeAlso">oci_fetch_all()</a> - Fetches multiple rows from a query into a two-dimensional array</span></li>
    <li><span class="function"><a href="function.oci-fetch-assoc.php" class="function" rel="rdfs-seeAlso">oci_fetch_assoc()</a> - Returns the next row from a query as an associative array</span></li>
    <li><span class="function"><a href="function.oci-fetch-array.php" class="function" rel="rdfs-seeAlso">oci_fetch_array()</a> - Returns the next row from a query as an associative or numeric array</span></li>
    <li><span class="function"><a href="function.oci-fetch-row.php" class="function" rel="rdfs-seeAlso">oci_fetch_row()</a> - Returns the next row from a query as a numeric array</span></li>
   </ul>
  </p>
 </div>


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