<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/class.mysqli.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'fr',
  ),
  'this' => 
  array (
    0 => 'mysqli.multi-query.php',
    1 => 'mysqli::multi_query',
    2 => 'Ex&eacute;cute une ou plusieurs requ&ecirc;tes sur la base de donn&eacute;es',
  ),
  'up' => 
  array (
    0 => 'class.mysqli.php',
    1 => 'mysqli',
  ),
  'prev' => 
  array (
    0 => 'mysqli.more-results.php',
    1 => 'mysqli::more_results',
  ),
  'next' => 
  array (
    0 => 'mysqli.next-result.php',
    1 => 'mysqli::next_result',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'fr',
    'path' => 'reference/mysqli/mysqli/multi-query.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="mysqli.multi-query" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">mysqli::multi_query</h1>
  <h1 class="refname">mysqli_multi_query</h1>
  <p class="verinfo">(PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">mysqli::multi_query</span> -- <span class="refname">mysqli_multi_query</span> &mdash; <span class="dc-title">Exécute une ou plusieurs requêtes sur la base de données</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-mysqli.multi-query-description">
  <h3 class="title">Description</h3>
  <p class="para">Style orienté objet</p>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>mysqli::multi_query</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$query</code></span>): <span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span></div>

  <p class="para rdfs-comment">Style procédural</p>
  <div class="methodsynopsis dc-description"><span class="methodname"><strong>mysqli_multi_query</strong></span>(<span class="methodparam"><span class="type"><a href="class.mysqli.php" class="type mysqli">mysqli</a></span> <code class="parameter">$mysql</code></span>, <span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$query</code></span>): <span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span></div>

  <p class="para rdfs-comment">
   Exécute une ou plusieurs requêtes, rassemblées dans le paramètre
   <code class="parameter">query</code> par des points-virgules.
  </p>
  <div class="warning"><strong class="warning">Avertissement</strong>
 <h1 class="title">Avertissement de Sécurité : injection SQL</h1>
 <p class="para">Si la requête contiens des variables d&#039;entrées alors des
 <a href="mysqli.quickstart.prepared-statements.php" class="link">déclarations préparées paramétrisées</a>
 devrait être utilisé à la place. Alternativement, les données doivent être correctement
 formatées et toutes les chaînes de caractères doivent être échappées en utilisant la fonction
 <span class="function"><a href="mysqli.real-escape-string.php" class="function">mysqli_real_escape_string()</a></span>.</p>
</div>
  <p class="para">
   Les requêtes sont envoyées en un seul appel à la base de données et traitées séquentiellement.
   <span class="methodname"><strong>mysqli_multi_query()</strong></span> attend que la première requête
   soit terminée avant de rendre le contrôle à PHP. Entre-temps, le serveur MySQL
   continue de traiter les requêtes restantes de manière asynchrone par rapport à PHP
   et rend les résultats disponibles pour la récupération.
  </p>
  <p class="para">
   Il est recommandé d&#039;utiliser une
   <a href="control-structures.do.while.php" class="link">do-while</a> pour traiter
   plusieurs requêtes. La connexion sera occupée jusqu&#039;à ce que toutes les
   requêtes soient complétées et que leur résultat soit récupéré par PHP.
   Aucune autre requête ne peut être émise sur la même connexion, jusqu&#039;à ce
   que toutes les requêtes soient traitées.
   Pour traiter la prochaine requête dans la suite, utiliser
   <span class="function"><a href="mysqli.next-result.php" class="function">mysqli_next_result()</a></span>. Si le prochain résultat n&#039;est pas
   encore prêt mysqli attendra pour la réponse depuis le serveur MySQL.
   Pour vérifier s&#039;il y a plus de résultats, utiliser
   <span class="function"><a href="mysqli.more-results.php" class="function">mysqli_more_results()</a></span>.
  </p>
  <p class="para">
   Pour les requêtes qui produisent un jeu de résultat, tel que
   <code class="literal">SELECT, SHOW, DESCRIBE</code> ou
   <code class="literal">EXPLAIN</code>,
   <span class="function"><a href="mysqli.use-result.php" class="function">mysqli_use_result()</a></span> ou <span class="function"><a href="mysqli.store-result.php" class="function">mysqli_store_result()</a></span>
   peut être utilisé pour récupérer le jeu de résultat. Pour les requêtes qui
   ne produisent pas de jeu de résultat, les mêmes fonctions peuvent être
   utilisées pour récupérer les informations telles que le nombre de lignes affectées.
  </p>
  <div class="tip"><strong class="tip">Astuce</strong>
   <p class="para">
    Exécuter une requête <code class="literal">CALL</code> pour les procédures stockées
    peut produire plusieurs jeux de résultats. Si la procédure stockée contient
    des requêtes <code class="literal">SELECT</code>, les jeux de résultats sont retournés
    dans l&#039;ordre dans lequel ils sont produits par l&#039;exécution de la procédure.
    En général, l&#039;appeleur ne peut pas savoir combien de jeux de résultats une
    procédure retournera et doit être préparé à récupérer plusieurs résultats.
    Le résultat final de la procédure est un résultat de statut qui n&#039;inclut
    pas de jeu de résultat. Le statut indique si la procédure a succédé
    ou si une erreur s&#039;est produite.
   </p>
  </div>
 </div>


 <div class="refsect1 parameters" id="refsect1-mysqli.multi-query-parameters">
  <h3 class="title">Liste de paramètres</h3>
  <p class="para">
   <dl>
    
<dt><code class="parameter">mysql</code></dt><dd><p class="para">
 Seulement en style procédural : Un objet <span class="classname"><a href="class.mysqli.php" class="classname">mysqli</a></span>
 retourné par la fonction <span class="function"><a href="function.mysqli-connect.php" class="function">mysqli_connect()</a></span> ou <span class="function"><a href="mysqli.init.php" class="function">mysqli_init()</a></span>.
</p></dd>
    
     <dt><code class="parameter">query</code></dt>
     <dd>
      <p class="para">
       Une <a href="language.types.string.php" class="link">chaîne de caractères</a> contenant les requêtes à exécuter.
       Plusieurs requêtes doivent être séparées par un point-virgule.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-mysqli.multi-query-returnvalues">
  <h3 class="title">Valeurs de retour</h3>
  <p class="para">
   Retourne <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> uniquement si la première requête échoue. Pour récupérer
   les sous-séquences d&#039;erreurs issues des autres requêtes, il faut appeler
   d&#039;abord la fonction <span class="function"><a href="mysqli.next-result.php" class="function">mysqli_next_result()</a></span>.
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-mysqli.multi-query-errors">
  <h3 class="title">Erreurs / Exceptions</h3>
  <p class="para">
Si le rapport d&#039;erreurs mysqli est activé (<strong><code><a href="mysqli.constants.php#constant.mysqli-report-error">MYSQLI_REPORT_ERROR</a></code></strong>) et que l&#039;opération demandée échoue,
un avertissement est généré. Si, en plus, le mode est défini sur <strong><code><a href="mysqli.constants.php#constant.mysqli-report-strict">MYSQLI_REPORT_STRICT</a></code></strong>,
une <span class="classname"><a href="class.mysqli-sql-exception.php" class="classname">mysqli_sql_exception</a></span> est lancée à la place.</p>
 </div>


 <div class="refsect1 examples" id="refsect1-mysqli.multi-query-examples">
  <h3 class="title">Exemples</h3>
  <div class="example" id="example-1">
   <p><strong>Exemple #1 Exemple avec <span class="methodname"><strong>mysqli::multi_query()</strong></span></strong></p>
   <div class="example-contents"><p>Style orienté objet</p></div>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />mysqli_report</span><span style="color: #007700">(</span><span style="color: #0000BB">MYSQLI_REPORT_ERROR </span><span style="color: #007700">| </span><span style="color: #0000BB">MYSQLI_REPORT_STRICT</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$mysqli </span><span style="color: #007700">= new </span><span style="color: #0000BB">mysqli</span><span style="color: #007700">(</span><span style="color: #DD0000">"localhost"</span><span style="color: #007700">, </span><span style="color: #DD0000">"my_user"</span><span style="color: #007700">, </span><span style="color: #DD0000">"my_password"</span><span style="color: #007700">, </span><span style="color: #DD0000">"world"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$query </span><span style="color: #007700">= </span><span style="color: #DD0000">"SELECT CURRENT_USER();"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$query </span><span style="color: #007700">.= </span><span style="color: #DD0000">"SELECT Name FROM City ORDER BY ID LIMIT 20, 5"</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">/* Exécution d'une requête multiple */<br /></span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">multi_query</span><span style="color: #007700">(</span><span style="color: #0000BB">$query</span><span style="color: #007700">);<br />do {<br />    </span><span style="color: #FF8000">/* store the result set in PHP */<br />    </span><span style="color: #007700">if (</span><span style="color: #0000BB">$result </span><span style="color: #007700">= </span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">store_result</span><span style="color: #007700">()) {<br />        while (</span><span style="color: #0000BB">$row </span><span style="color: #007700">= </span><span style="color: #0000BB">$result</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">fetch_row</span><span style="color: #007700">()) {<br />            </span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"%s\n"</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">]);<br />        }<br />    }<br />    </span><span style="color: #FF8000">/* print divider */<br />    </span><span style="color: #007700">if (</span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">more_results</span><span style="color: #007700">()) {<br />        </span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"-----------------\n"</span><span style="color: #007700">);<br />    }<br />} while (</span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">next_result</span><span style="color: #007700">());<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
   </div>

   <div class="example-contents"><p>Style procédural</p></div>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />mysqli_report</span><span style="color: #007700">(</span><span style="color: #0000BB">MYSQLI_REPORT_ERROR </span><span style="color: #007700">| </span><span style="color: #0000BB">MYSQLI_REPORT_STRICT</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$link </span><span style="color: #007700">= </span><span style="color: #0000BB">mysqli_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">"localhost"</span><span style="color: #007700">, </span><span style="color: #DD0000">"my_user"</span><span style="color: #007700">, </span><span style="color: #DD0000">"my_password"</span><span style="color: #007700">, </span><span style="color: #DD0000">"world"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$query </span><span style="color: #007700">= </span><span style="color: #DD0000">"SELECT CURRENT_USER();"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$query </span><span style="color: #007700">.= </span><span style="color: #DD0000">"SELECT Name FROM City ORDER BY ID LIMIT 20, 5"</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">/* Exécution d'une requête multiple */<br /></span><span style="color: #0000BB">mysqli_multi_query</span><span style="color: #007700">(</span><span style="color: #0000BB">$link</span><span style="color: #007700">, </span><span style="color: #0000BB">$query</span><span style="color: #007700">);<br />do {<br />    </span><span style="color: #FF8000">/* store the result set in PHP */<br />    </span><span style="color: #007700">if (</span><span style="color: #0000BB">$result </span><span style="color: #007700">= </span><span style="color: #0000BB">mysqli_store_result</span><span style="color: #007700">(</span><span style="color: #0000BB">$link</span><span style="color: #007700">)) {<br />        while (</span><span style="color: #0000BB">$row </span><span style="color: #007700">= </span><span style="color: #0000BB">mysqli_fetch_row</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">)) {<br />            </span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"%s\n"</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">]);<br />        }<br />        </span><span style="color: #FF8000">/* Affichage d'une séparation */<br />        </span><span style="color: #007700">if (</span><span style="color: #0000BB">mysqli_more_results</span><span style="color: #007700">(</span><span style="color: #0000BB">$link</span><span style="color: #007700">)) {<br />            </span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"-----------------\n"</span><span style="color: #007700">);<br />        }<br />    }<br />    </span><span style="color: #FF8000">/* print divider */<br />    </span><span style="color: #007700">if (</span><span style="color: #0000BB">mysqli_more_results</span><span style="color: #007700">(</span><span style="color: #0000BB">$link</span><span style="color: #007700">)) {<br />        </span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"-----------------\n"</span><span style="color: #007700">);<br />    }<br />} while (</span><span style="color: #0000BB">mysqli_next_result</span><span style="color: #007700">(</span><span style="color: #0000BB">$link</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
   </div>

   <div class="example-contents"><p>Les exemples ci-dessus vont afficher quelque chose de similaire à :</p></div>
   <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">my_user@localhost
-----------------
Amersfoort
Maastricht
Dordrecht
Leiden
Haarlemmermeer</pre>
</div>
   </div>
  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-mysqli.multi-query-seealso">
  <h3 class="title">Voir aussi</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="mysqli.query.php" class="function" rel="rdfs-seeAlso">mysqli_query()</a> - Ex&eacute;cute une requ&ecirc;te sur la base de donn&eacute;es</span></li>
    <li><span class="function"><a href="mysqli.use-result.php" class="function" rel="rdfs-seeAlso">mysqli_use_result()</a> - Initialise la r&eacute;cup&eacute;ration d'un jeu de r&eacute;sultats</span></li>
    <li><span class="function"><a href="mysqli.store-result.php" class="function" rel="rdfs-seeAlso">mysqli_store_result()</a> - Transf&egrave;re un jeu de r&eacute;sultats &agrave; partir de la derni&egrave;re requ&ecirc;te</span></li>
    <li><span class="function"><a href="mysqli.next-result.php" class="function" rel="rdfs-seeAlso">mysqli_next_result()</a> - Pr&eacute;pare le prochain r&eacute;sultat d'une requ&ecirc;te multiple</span></li>
    <li><span class="function"><a href="mysqli.more-results.php" class="function" rel="rdfs-seeAlso">mysqli_more_results()</a> - V&eacute;rifie s'il y a d'autres jeux de r&eacute;sultats MySQL disponibles</span></li>
   </ul>
  </p>
 </div>


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