<?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 => 'fr',
  ),
  'this' => 
  array (
    0 => 'function.oci-fetch.php',
    1 => 'oci_fetch',
    2 => 'Lit la prochaine ligne d\'un r&eacute;sultat Oracle dans un buffer interne',
  ),
  'up' => 
  array (
    0 => 'ref.oci8.php',
    1 => 'Fonctions OCI8',
  ),
  'prev' => 
  array (
    0 => 'function.oci-execute.php',
    1 => 'oci_execute',
  ),
  'next' => 
  array (
    0 => 'function.oci-fetch-all.php',
    1 => 'oci_fetch_all',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'fr',
    'path' => 'reference/oci8/functions/oci-fetch.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.oci-fetch" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">oci_fetch</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</span> &mdash; <span class="dc-title">Lit la prochaine ligne d&#039;un résultat Oracle dans un buffer interne</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.oci-fetch-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>oci_fetch</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="type"><a href="language.types.boolean.php" class="type bool">bool</a></span></div>

  <p class="para rdfs-comment">
   Lit la prochaine ligne d&#039;une requête dans un buffer interne accessible
   soit via la fonction <span class="function"><a href="function.oci-result.php" class="function">oci_result()</a></span>, soit en utilisant
   les variables précédemment définies avec la fonction
   <span class="function"><a href="function.oci-define-by-name.php" class="function">oci_define_by_name()</a></span>.
  </p>
  <p class="para">
   Voir la fonction <span class="function"><a href="function.oci-fetch-array.php" class="function">oci_fetch_array()</a></span> pour des
   informations génériques sur la récupération de données.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.oci-fetch-parameters">
  <h3 class="title">Liste de paramètres</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">statement</code></dt>
     <dd>
      <p class="para">Un identifiant de requête OCI8
créé par la fonction <span class="function"><a href="function.oci-parse.php" class="function">oci_parse()</a></span> et exécuté par la fonction
<span class="function"><a href="function.oci-execute.php" class="function">oci_execute()</a></span>, ou un identifiant de requête <code class="literal">REF
    CURSOR</code>.</p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.oci-fetch-returnvalues">
  <h3 class="title">Valeurs de retour</h3>
  <p class="para">
   Retourne <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong> en cas de succès, ou <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> s&#039;il n&#039;y a plus de lignes
   disponibles pour la requête <code class="parameter">statement</code>.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.oci-fetch-examples">
  <h3 class="title">Exemples</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Exemple #1 Exemple avec <span class="function"><strong>oci_fetch()</strong></span> avec des variables définies</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br />$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">$sql </span><span style="color: #007700">= </span><span style="color: #DD0000">'SELECT location_id, city FROM locations WHERE location_id &lt; 1200'</span><span style="color: #007700">;<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: #0000BB">$sql</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// La définition doit s'effectuer AVANT l'exécution<br /></span><span style="color: #0000BB">oci_define_by_name</span><span style="color: #007700">(</span><span style="color: #0000BB">$stid</span><span style="color: #007700">, </span><span style="color: #DD0000">'LOCATION_ID'</span><span style="color: #007700">, </span><span style="color: #0000BB">$locid</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">oci_define_by_name</span><span style="color: #007700">(</span><span style="color: #0000BB">$stid</span><span style="color: #007700">, </span><span style="color: #DD0000">'CITY'</span><span style="color: #007700">, </span><span style="color: #0000BB">$city</span><span style="color: #007700">);<br /><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 /></span><span style="color: #FF8000">// Chaque récupération utilise les variables précédemment définies avec les données de la prochaine ligne<br /></span><span style="color: #007700">while (</span><span style="color: #0000BB">oci_fetch</span><span style="color: #007700">(</span><span style="color: #0000BB">$stid</span><span style="color: #007700">)) {<br />    echo </span><span style="color: #DD0000">"Location id </span><span style="color: #0000BB">$locid</span><span style="color: #DD0000"> is </span><span style="color: #0000BB">$city</span><span style="color: #DD0000">&lt;br&gt;\n"</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #FF8000">// Affiche :<br />//   Location id 1000 is Roma<br />//   Location id 1100 is Venice<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>Exemple #2 Exemple avec <span class="function"><strong>oci_fetch()</strong></span> et <span class="function"><a href="function.oci-result.php" class="function">oci_result()</a></span></strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br />$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">$sql </span><span style="color: #007700">= </span><span style="color: #DD0000">'SELECT location_id, city FROM locations WHERE location_id &lt; 1200'</span><span style="color: #007700">;<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: #0000BB">$sql</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">oci_fetch</span><span style="color: #007700">(</span><span style="color: #0000BB">$stid</span><span style="color: #007700">)) {<br />    echo </span><span style="color: #0000BB">oci_result</span><span style="color: #007700">(</span><span style="color: #0000BB">$stid</span><span style="color: #007700">, </span><span style="color: #DD0000">'LOCATION_ID'</span><span style="color: #007700">) . </span><span style="color: #DD0000">" is "</span><span style="color: #007700">;<br />    echo </span><span style="color: #0000BB">oci_result</span><span style="color: #007700">(</span><span style="color: #0000BB">$stid</span><span style="color: #007700">, </span><span style="color: #DD0000">'CITY'</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">// Affiche :<br />//   1000 is Roma<br />//   1100 is Venice<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 notes" id="refsect1-function.oci-fetch-notes">
  <h3 class="title">Notes</h3>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    Cette fonction ne retournera pas de lignes depuis le jeu de
    résultats implicite depuis une base de données Oracle.
    Utiliser plutôt la fonction
    <span class="function"><a href="function.oci-fetch-array.php" class="function">oci_fetch_array()</a></span>.
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.oci-fetch-seealso">
  <h3 class="title">Voir aussi</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.oci-define-by-name.php" class="function" rel="rdfs-seeAlso">oci_define_by_name()</a> - Associe une variable PHP avec une colonne pour une requ&ecirc;te de r&eacute;cup&eacute;ration de donn&eacute;es</span></li>
    <li><span class="function"><a href="function.oci-fetch-all.php" class="function" rel="rdfs-seeAlso">oci_fetch_all()</a> - Lit plusieurs lignes d'un r&eacute;sultat dans un tableau multidimensionnel</span></li>
    <li><span class="function"><a href="function.oci-fetch-array.php" class="function" rel="rdfs-seeAlso">oci_fetch_array()</a> - Lit une ligne d'un r&eacute;sultat sous forme de tableau associatif ou num&eacute;rique</span></li>
    <li><span class="function"><a href="function.oci-fetch-assoc.php" class="function" rel="rdfs-seeAlso">oci_fetch_assoc()</a> - Lit une ligne d'un r&eacute;sultat sous forme de tableau associatif</span></li>
    <li><span class="function"><a href="function.oci-fetch-object.php" class="function" rel="rdfs-seeAlso">oci_fetch_object()</a> - Lit une ligne d'un r&eacute;sultat sous forme d'objet</span></li>
    <li><span class="function"><a href="function.oci-fetch-row.php" class="function" rel="rdfs-seeAlso">oci_fetch_row()</a> - Lit la prochaine ligne d'une requ&ecirc;te sous forme de tableau num&eacute;rique</span></li>
    <li><span class="function"><a href="function.oci-result.php" class="function" rel="rdfs-seeAlso">oci_result()</a> - Retourne la valeur d'une colonne dans un r&eacute;sultat Oracle</span></li>
   </ul>
  </p>
 </div>


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