<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.mysql.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'fr',
  ),
  'this' => 
  array (
    0 => 'function.mysql-fetch-array.php',
    1 => 'mysql_fetch_array',
    2 => 'Retourne une ligne de r&eacute;sultat MySQL sous la forme d\'un tableau
   associatif, d\'un tableau index&eacute;, ou les deux',
  ),
  'up' => 
  array (
    0 => 'ref.mysql.php',
    1 => 'Fonctions MySQL',
  ),
  'prev' => 
  array (
    0 => 'function.mysql-escape-string.php',
    1 => 'mysql_escape_string',
  ),
  'next' => 
  array (
    0 => 'function.mysql-fetch-assoc.php',
    1 => 'mysql_fetch_assoc',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'fr',
    'path' => 'reference/mysql/functions/mysql-fetch-array.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.mysql-fetch-array" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">mysql_fetch_array</h1>
  <p class="verinfo">(PHP 4, PHP 5)</p><p class="refpurpose"><span class="refname">mysql_fetch_array</span> &mdash; <span class="dc-title">
   Retourne une ligne de résultat MySQL sous la forme d&#039;un tableau
   associatif, d&#039;un tableau indexé, ou les deux
  </span></p>

 </div>

 <div id="function.mysql-fetch-array-refsynopsisdiv">
  <div class="warning"><strong class="warning">Avertissement</strong>
   <p class="para">Cette extension
était obsolète en PHP 5.5.0, et a été supprimée en PHP 7.0.0. À la place, vous pouvez
utiliser l&#039;extension <a href="book.mysqli.php" class="link">MySQLi</a> ou l&#039;extension
<a href="ref.pdo-mysql.php" class="link">PDO_MySQL</a>. Voir aussi
<a href="mysqlinfo.api.choosing.php" class="link">MySQL : choisir une API</a> du guide.
Alternatives à cette fonction :</p>
   <ul class="simplelist">
    <li><span class="function"><a href="mysqli-result.fetch-array.php" class="function">mysqli_fetch_array()</a></span></li>
    <li><span class="methodname"><a href="pdostatement.fetch.php" class="methodname">PDOStatement::fetch()</a></span></li>
   </ul>
  </div>
 </div>

 <div class="refsect1 description" id="refsect1-function.mysql-fetch-array-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>mysql_fetch_array</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.resource.php" class="type resource">resource</a></span> <code class="parameter">$result</code></span>, <span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$result_type</code><span class="initializer"> = MYSQL_BOTH</span></span>): <span class="type"><a href="language.types.array.php" class="type array">array</a></span></div>

  <p class="simpara">
   <span class="function"><strong>mysql_fetch_array()</strong></span> retourne un tableau qui
   contient la ligne demandée dans le résultat <code class="parameter">result</code>
   et déplace le pointeur de données interne d&#039;un cran.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.mysql-fetch-array-parameters">
  <h3 class="title">Liste de paramètres</h3>
  <dl>
   
<dt><code class="parameter">result</code></dt><dd><p class="para">
 La <span class="type"><a href="language.types.resource.php" class="type resource">resource</a></span> de résultat qui vient d&#039;être évaluée.
 Ce résultat vient de l&#039;appel à la fonction <span class="function"><a href="function.mysql-query.php" class="function">mysql_query()</a></span>.
</p></dd>
   
    <dt><code class="parameter">result_type</code></dt>
    <dd>
     <span class="simpara">
      Le type de tableau à récupérer. C&#039;est une constante qui peut prendre
      les valeurs suivantes : <strong><code><a href="mysql.constants.php#constant.mysql-assoc">MYSQL_ASSOC</a></code></strong>,
      <strong><code><a href="mysql.constants.php#constant.mysql-num">MYSQL_NUM</a></code></strong>, et
      <strong><code><a href="mysql.constants.php#constant.mysql-both">MYSQL_BOTH</a></code></strong>.
     </span>
    </dd>
   
  </dl>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.mysql-fetch-array-returnvalues">
  <h3 class="title">Valeurs de retour</h3>
  <p class="simpara">
   Retourne un tableau de chaînes qui correspond à la ligne récupérée ou <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>
   s&#039;il n&#039;y a plus de lignes. Le type de tableau retourné dépend de la
   définition du paramètre <code class="parameter">result_type</code>.
   En utilisant <strong><code><a href="mysql.constants.php#constant.mysql-both">MYSQL_BOTH</a></code></strong> (défaut), l&#039;on
   récupérera un tableau contenant des indices associatifs et numériques.
   En utilisant <strong><code><a href="mysql.constants.php#constant.mysql-assoc">MYSQL_ASSOC</a></code></strong>, on ne récupérera que
   les indices associatifs (comme le fonctionnement de la fonction
   <span class="function"><a href="function.mysql-fetch-assoc.php" class="function">mysql_fetch_assoc()</a></span>), en utilisant <strong><code><a href="mysql.constants.php#constant.mysql-num">MYSQL_NUM</a></code></strong>,
   on ne récupérera que les indices numériques (comme le fonctionnement
   de la fonction <span class="function"><a href="function.mysql-fetch-row.php" class="function">mysql_fetch_row()</a></span>).
  </p>
  <p class="simpara">
   Si plusieurs colonnes portent le même nom, la dernière colonne
   aura la priorité. Pour accéder aux autres colonnes du
   même nom, il faut utiliser l&#039;index numérique, ou
   faire un alias pour chaque colonne. Pour les alias de colonnes,
   il ne sera pas possible d&#039;accéder aux contenus avec les noms originaux
   des colonnes.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.mysql-fetch-array-examples">
  <h3 class="title">Exemples</h3>
  <div class="example" id="example-1">
   <p><strong>Exemple #1 Requête avec duplication de nom de colonnes</strong></p>
   <div class="example-contents">
<div class="sqlcode"><pre class="sqlcode">SELECT table1.field AS foo, table2.field AS bar FROM table1, table2</pre>
</div>
   </div>

  </div>
  <div class="example" id="example-2">
   <p><strong>Exemple #2 <span class="function"><strong>mysql_fetch_array()</strong></span> avec <strong><code><a href="mysql.constants.php#constant.mysql-num">MYSQL_NUM</a></code></strong></strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />mysql_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">"localhost"</span><span style="color: #007700">, </span><span style="color: #DD0000">"mysql_user"</span><span style="color: #007700">, </span><span style="color: #DD0000">"mysql_password"</span><span style="color: #007700">) or<br />die(</span><span style="color: #DD0000">"Impossible de se connecter : " </span><span style="color: #007700">. </span><span style="color: #0000BB">mysql_error</span><span style="color: #007700">());<br /></span><span style="color: #0000BB">mysql_select_db</span><span style="color: #007700">(</span><span style="color: #DD0000">"mydb"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$result </span><span style="color: #007700">= </span><span style="color: #0000BB">mysql_query</span><span style="color: #007700">(</span><span style="color: #DD0000">"SELECT id, name FROM mytable"</span><span style="color: #007700">);<br /><br />while (</span><span style="color: #0000BB">$row </span><span style="color: #007700">= </span><span style="color: #0000BB">mysql_fetch_array</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">, </span><span style="color: #0000BB">MYSQL_NUM</span><span style="color: #007700">)) {<br />   </span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"ID : %s  Nom : %s"</span><span style="color: #007700">, </span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #0000BB">0</span><span style="color: #007700">], </span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #0000BB">1</span><span style="color: #007700">]);<br />}<br /><br /></span><span style="color: #0000BB">mysql_free_result</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
   </div>

  </div>
  <div class="example" id="example-3">
   <p><strong>Exemple #3 <span class="function"><strong>mysql_fetch_array()</strong></span> avec <strong><code><a href="mysql.constants.php#constant.mysql-assoc">MYSQL_ASSOC</a></code></strong></strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />mysql_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">"localhost"</span><span style="color: #007700">, </span><span style="color: #DD0000">"mysql_user"</span><span style="color: #007700">, </span><span style="color: #DD0000">"mysql_password"</span><span style="color: #007700">) or<br />die(</span><span style="color: #DD0000">"Impossible de se connecter : " </span><span style="color: #007700">. </span><span style="color: #0000BB">mysql_error</span><span style="color: #007700">());<br /></span><span style="color: #0000BB">mysql_select_db</span><span style="color: #007700">(</span><span style="color: #DD0000">"mydb"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$result </span><span style="color: #007700">= </span><span style="color: #0000BB">mysql_query</span><span style="color: #007700">(</span><span style="color: #DD0000">"SELECT id, name FROM mytable"</span><span style="color: #007700">);<br /><br />while (</span><span style="color: #0000BB">$row </span><span style="color: #007700">= </span><span style="color: #0000BB">mysql_fetch_array</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">, </span><span style="color: #0000BB">MYSQL_ASSOC</span><span style="color: #007700">)) {<br />   </span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"ID : %s  Nom : %s"</span><span style="color: #007700">, </span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #DD0000">"id"</span><span style="color: #007700">], </span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #DD0000">"name"</span><span style="color: #007700">]);<br />}<br /><br /></span><span style="color: #0000BB">mysql_free_result</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
   </div>

  </div>
  <div class="example" id="example-4">
   <p><strong>Exemple #4 <span class="function"><strong>mysql_fetch_array()</strong></span> avec <strong><code><a href="mysql.constants.php#constant.mysql-both">MYSQL_BOTH</a></code></strong></strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />mysql_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">"localhost"</span><span style="color: #007700">, </span><span style="color: #DD0000">"mysql_user"</span><span style="color: #007700">, </span><span style="color: #DD0000">"mysql_password"</span><span style="color: #007700">) or<br />die(</span><span style="color: #DD0000">"Impossible de se connecter : " </span><span style="color: #007700">. </span><span style="color: #0000BB">mysql_error</span><span style="color: #007700">());<br /></span><span style="color: #0000BB">mysql_select_db</span><span style="color: #007700">(</span><span style="color: #DD0000">"mydb"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$result </span><span style="color: #007700">= </span><span style="color: #0000BB">mysql_query</span><span style="color: #007700">(</span><span style="color: #DD0000">"SELECT id, name FROM mytable"</span><span style="color: #007700">);<br /><br />while (</span><span style="color: #0000BB">$row </span><span style="color: #007700">= </span><span style="color: #0000BB">mysql_fetch_array</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">, </span><span style="color: #0000BB">MYSQL_BOTH</span><span style="color: #007700">)) {<br />   </span><span style="color: #0000BB">printf </span><span style="color: #007700">(</span><span style="color: #DD0000">"ID : %s  Nom : %s"</span><span style="color: #007700">, </span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #0000BB">0</span><span style="color: #007700">], </span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #DD0000">"name"</span><span style="color: #007700">]);<br />}<br /><br /></span><span style="color: #0000BB">mysql_free_result</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
   </div>

  </div>
 </div>


 <div class="refsect1 notes" id="refsect1-function.mysql-fetch-array-notes">
  <h3 class="title">Notes</h3>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <strong>Performance</strong><br />
   <span class="simpara">
    Une chose importante à noter est que l&#039;utilisation de
    <span class="function"><strong>mysql_fetch_array()</strong></span> n&#039;est <em>pas
    significativement</em> plus lente que l&#039;utilisation de
    <span class="function"><a href="function.mysql-fetch-row.php" class="function">mysql_fetch_row()</a></span>, alors qu&#039;elle fournit
    une valeur ajoutée significative.
   </span>
  </p></blockquote>
  <blockquote class="note"><p><strong class="note">Note</strong>: <span class="simpara">Les noms des champs retournés par
    cette fonction sont <em>sensibles à la casse</em>.</span></p></blockquote>
  <blockquote class="note"><p><strong class="note">Note</strong>: <span class="simpara">Cette fonction définit les champs NULL à la
    valeur PHP <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong>.</span></p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.mysql-fetch-array-seealso">
  <h3 class="title">Voir aussi</h3>
  <ul class="simplelist">
   <li><span class="function"><a href="function.mysql-fetch-row.php" class="function" rel="rdfs-seeAlso">mysql_fetch_row()</a> - Retourne une ligne de r&eacute;sultat MySQL sous la forme d'un tableau</span></li>
   <li><span class="function"><a href="function.mysql-fetch-assoc.php" class="function" rel="rdfs-seeAlso">mysql_fetch_assoc()</a> - Lit une ligne de r&eacute;sultat MySQL dans un tableau associatif</span></li>
   <li><span class="function"><a href="function.mysql-data-seek.php" class="function" rel="rdfs-seeAlso">mysql_data_seek()</a> - D&eacute;place le pointeur interne de r&eacute;sultat MySQL</span></li>
   <li><span class="function"><a href="function.mysql-query.php" class="function" rel="rdfs-seeAlso">mysql_query()</a> - Envoie une requ&ecirc;te &agrave; un serveur MySQL</span></li>
  </ul>
 </div>

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