<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/class.pdo.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'fr',
  ),
  'this' => 
  array (
    0 => 'pdo.quote.php',
    1 => 'PDO::quote',
    2 => 'Prot&egrave;ge une cha&icirc;ne pour l\'utiliser dans une requ&ecirc;te SQL PDO',
  ),
  'up' => 
  array (
    0 => 'class.pdo.php',
    1 => 'PDO',
  ),
  'prev' => 
  array (
    0 => 'pdo.query.php',
    1 => 'PDO::query',
  ),
  'next' => 
  array (
    0 => 'pdo.rollback.php',
    1 => 'PDO::rollBack',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'fr',
    'path' => 'reference/pdo/pdo/quote.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="pdo.quote" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">PDO::quote</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.1.0, PHP 7, PHP 8, PECL pdo &gt;= 0.2.1)</p><p class="refpurpose"><span class="refname">PDO::quote</span> &mdash; <span class="dc-title">
   Protège une chaîne pour l&#039;utiliser dans une requête SQL PDO
  </span></p>

 </div>
 <div class="refsect1 description" id="refsect1-pdo.quote-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>PDO::quote</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$string</code></span>, <span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$type</code><span class="initializer"> = <strong><code><a href="pdo.constants.php#pdo.constants.param-str">PDO::PARAM_STR</a></code></strong></span></span>): <span class="type"><span class="type"><a href="language.types.string.php" class="type string">string</a></span>|<span class="type"><a href="language.types.singleton.php" class="type false">false</a></span></span></div>


  <p class="para rdfs-comment">
   <span class="methodname"><strong>PDO::quote()</strong></span> place des guillemets simples autour
   d&#039;une chaîne d&#039;entrée et protège les caractères spéciaux présents dans la
   chaîne d&#039;entrée, en utilisant le style de protection approprié au pilote courant.
  </p>
  <p class="para">
   Lors de l&#039;utilisation de cette fonction pour construire des requêtes SQL, l&#039;on est
   <em>vivement</em> invités à utiliser
   <span class="methodname"><a href="pdo.prepare.php" class="methodname">PDO::prepare()</a></span> pour préparer les requêtes SQL avec
   des paramètres liés au lieu d&#039;utiliser <span class="methodname"><strong>PDO::quote()</strong></span> pour
   interpréter les entrées utilisateur dans la requête SQL. Les requêtes préparées
   avec des paramètres liés sont non seulement plus portables, plus souples et
   plus sécuritaires, mais bien plus rapides à exécuter que d&#039;interpréter les
   requêtes, étant donné que les côtés client et serveur peuvent mettre
   en cache une version compilée de la requête.
  </p>
  <p class="para">
   Tous les pilotes PDO n&#039;implémentent pas cette méthode (comme PDO_ODBC). Utiliser
   les requêtes préparées à la place.
  </p>
  <div class="caution"><strong class="caution">Attention</strong>
   <h1 class="title">Sécurité : le jeu de caractères par défaut</h1>
   <p class="para">
    Le jeu de caractères doit être défini soit au niveau
    du serveur, soit lors de la connexion à la base de
    données (suivant le driver utilisé) pour qu&#039;il affecte
    la méthode <span class="methodname"><strong>PDO::quote()</strong></span>.
    Voir la <a href="pdo.drivers.php" class="link">documentation
    spécifique au driver</a> pour plus d&#039;informations.
   </p>
  </div>
 </div>

 <div class="refsect1 parameters" id="refsect1-pdo.quote-parameters">
  <h3 class="title">Liste de paramètres</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">string</code></dt>
      <dd>
       <p class="para">
        La chaîne à protéger.
       </p>
      </dd>
     
    
     <dt><code class="parameter">type</code></dt>
      <dd>
       <p class="para">
        Le type de données pour les drivers qui ont des styles particuliers
        de protection.
        Fournit un indice au type de donnée pour les pilotes qui ont un style
        d&#039;échappement différent. Par exemple <strong><code>PDO_PARAM_LOB</code></strong>
        indique au pilote d&#039;échapper des données binaires.
       </p>
      </dd>
     
   </dl>
  </p>
 </div>

 <div class="refsect1 returnvalues" id="refsect1-pdo.quote-returnvalues">
  <h3 class="title">Valeurs de retour</h3>
  <p class="para">
   Retourne une chaîne protégée, qui est théoriquement sûre à utiliser
   dans une requête SQL. Retourne <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> si le pilote ne supporte pas
   ce type de protections.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-pdo.quote-examples">
  <h3 class="title">Exemples</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Exemple #1 Protection d&#039;une chaîne normale</strong></p>
    <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">= new </span><span style="color: #0000BB">PDO</span><span style="color: #007700">(</span><span style="color: #DD0000">'sqlite:/home/lynn/music.sql3'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/* Chaîne simple */<br /></span><span style="color: #0000BB">$string </span><span style="color: #007700">= </span><span style="color: #DD0000">'Nice'</span><span style="color: #007700">;<br />print </span><span style="color: #DD0000">"Chaîne non échappée : </span><span style="color: #0000BB">$string</span><span style="color: #DD0000">\n"</span><span style="color: #007700">;<br />print </span><span style="color: #DD0000">"Chaîne échappée : " </span><span style="color: #007700">. </span><span style="color: #0000BB">$conn</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">quote</span><span style="color: #007700">(</span><span style="color: #0000BB">$string</span><span style="color: #007700">) . </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>L&#039;exemple ci-dessus va afficher :</p></div>
    <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">Chaîne non échappée : Nice
Chaîne échappée: &#039;Nice&#039;</pre>
</div>
    </div>
   </div>
   <div class="example" id="example-2">
    <p><strong>Exemple #2 Protection d&#039;une chaîne dangereuse</strong></p>
    <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">= new </span><span style="color: #0000BB">PDO</span><span style="color: #007700">(</span><span style="color: #DD0000">'sqlite:/home/lynn/music.sql3'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/* Chaîne dangereuse */<br /></span><span style="color: #0000BB">$string </span><span style="color: #007700">= </span><span style="color: #DD0000">'Chaîne \' particulière'</span><span style="color: #007700">;<br />print </span><span style="color: #DD0000">"Chaîne non échappée : </span><span style="color: #0000BB">$string</span><span style="color: #DD0000">\n"</span><span style="color: #007700">;<br />print </span><span style="color: #DD0000">"Chaîne échappée :" </span><span style="color: #007700">. </span><span style="color: #0000BB">$conn</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">quote</span><span style="color: #007700">(</span><span style="color: #0000BB">$string</span><span style="color: #007700">) . </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>L&#039;exemple ci-dessus va afficher :</p></div>
    <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">Chaîne non échappée : Chaîne &#039; particulière
Chaîne échappée : &#039;Chaîne &#039;&#039; particulière&#039;</pre>
</div>
    </div>
   </div>
   <div class="example" id="example-3">
    <p><strong>Exemple #3 Protection d&#039;une chaîne complexe</strong></p>
    <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">= new </span><span style="color: #0000BB">PDO</span><span style="color: #007700">(</span><span style="color: #DD0000">'sqlite:/home/lynn/music.sql3'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/* Chaîne complexe */<br /></span><span style="color: #0000BB">$string </span><span style="color: #007700">= </span><span style="color: #DD0000">"Co'mpl''exe \"ch'\"aîne"</span><span style="color: #007700">;<br />print </span><span style="color: #DD0000">"Chaîne non échappée : </span><span style="color: #0000BB">$string</span><span style="color: #DD0000">\n"</span><span style="color: #007700">;<br />print </span><span style="color: #DD0000">"Chaîne échappée : " </span><span style="color: #007700">. </span><span style="color: #0000BB">$conn</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">quote</span><span style="color: #007700">(</span><span style="color: #0000BB">$string</span><span style="color: #007700">) . </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>L&#039;exemple ci-dessus va afficher :</p></div>
    <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">Chaîne non échappée: Co&#039;mpl&#039;&#039;exe &quot;ch&#039;&quot;aîne
Chaîne échappée: &#039;Co&#039;&#039;mpl&#039;&#039;&#039;&#039;exe &quot;ch&#039;&#039;&quot;aîne&#039;</pre>
</div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-pdo.quote-seealso">
  <h3 class="title">Voir aussi</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="methodname"><a href="pdo.prepare.php" class="methodname" rel="rdfs-seeAlso">PDO::prepare()</a> - Pr&eacute;pare une requ&ecirc;te &agrave; l'ex&eacute;cution et retourne un objet</span></li>
    <li><span class="methodname"><a href="pdostatement.execute.php" class="methodname" rel="rdfs-seeAlso">PDOStatement::execute()</a> - Ex&eacute;cute une requ&ecirc;te pr&eacute;par&eacute;e</span></li>
   </ul>
  </p>
 </div>


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