<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.pgsql.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'fr',
  ),
  'this' => 
  array (
    0 => 'function.pg-escape-bytea.php',
    1 => 'pg_escape_bytea',
    2 => 'Prot&egrave;ge une cha&icirc;ne pour insertion dans un champ bytea',
  ),
  'up' => 
  array (
    0 => 'ref.pgsql.php',
    1 => 'pg_cancel_query',
  ),
  'prev' => 
  array (
    0 => 'function.pg-end-copy.php',
    1 => 'pg_end_copy',
  ),
  'next' => 
  array (
    0 => 'function.pg-escape-identifier.php',
    1 => 'pg_escape_identifier',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'fr',
    'path' => 'reference/pgsql/functions/pg-escape-bytea.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.pg-escape-bytea" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">pg_escape_bytea</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.2.0, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">pg_escape_bytea</span> &mdash; <span class="dc-title">
   Protège une chaîne pour insertion dans un champ bytea
  </span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.pg-escape-bytea-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>pg_escape_bytea</strong></span>(<span class="methodparam"><span class="type"><a href="class.pgsql-connection.php" class="type PgSql\Connection">PgSql\Connection</a></span> <code class="parameter">$connection</code><span class="initializer"> = ?</span></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="type"><a href="language.types.string.php" class="type string">string</a></span></div>

  <p class="para rdfs-comment">
   <span class="function"><strong>pg_escape_bytea()</strong></span> protège les caractères de la
   chaîne <code class="parameter">string</code> avec le mode bytea. La chaîne
   protégée est retournée.
  </p>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    Lors de l&#039;utilisation d&#039;une commande <code class="literal">SELECT</code> avec des données de type bytea, 
    PostgreSQL retourne des valeurs octales, préfixées avec des antislashs
    &#039;\&#039; (par exemple \032). Les utilisateurs doivent effectuer la conversion en
    format binaire manuellement.
   </p>
   <p class="para">
    <span class="function"><strong>pg_escape_bytea()</strong></span> requiert PostgreSQL 7.2 ou plus récent. Avec
    PostgreSQL 7.2.0 et 7.2.1, les données bytea doivent être transtypées
    lorsque l&#039;on active le support des chaînes de caractères multioctets.
    C&#039;est-à-dire <code class="literal">INSERT INTO test_table (image) VALUES (&#039;$image_escaped&#039;::bytea);</code>.
    PostgreSQL 7.2.2 ou plus récent ne requiert pas cette manipulation.
    Toutefois, si le client et le serveur n&#039;utilisent pas le même jeu de caractères,
    il peut arriver des erreurs. Il faut alors forcer le transtypage
    manuellement.
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.pg-escape-bytea-parameters">
  <h3 class="title">Liste de paramètres</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">connection</code></dt>
     <dd>
      <p class="para">
 Une instance <span class="classname"><a href="class.pgsql-connection.php" class="classname">PgSql\Connection</a></span>.
 Quand <code class="parameter">connection</code> est pas spécifié, la connexion par défaut est utilisé.
 La connexion par défaut est la dernière connexion faite par
 <span class="function"><a href="function.pg-connect.php" class="function">pg_connect()</a></span> ou <span class="function"><a href="function.pg-pconnect.php" class="function">pg_pconnect()</a></span>
 <div class="warning"><strong class="warning">Avertissement</strong><p class="simpara">À partir de PHP 8.1.0, utiliser la connexion par défaut est obsolète.</p></div>
</p>
     </dd>
    
    
     <dt><code class="parameter">string</code></dt>
     <dd>
      <p class="para">
       Une <a href="language.types.string.php" class="link">chaîne de caractères</a> contenant du texte ou des données binaires qui seront
       insérées dans la colonne bytea.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.pg-escape-bytea-returnvalues">
  <h3 class="title">Valeurs de retour</h3>
  <p class="para">
   Une <a href="language.types.string.php" class="link">chaîne de caractères</a> contenant les données échappées.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.pg-escape-bytea-changelog">
  <h3 class="title">Historique</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>Version</th>
      <th>Description</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
 <td>8.1.0</td>
 <td>
  Le paramètre <code class="parameter">connection</code> attend désormais une instance de
  <span class="classname"><a href="class.pgsql-connection.php" class="classname">PgSql\Connection</a></span> ; auparavant, une <span class="type"><a href="language.types.resource.php" class="type resource">resource</a></span> était attendu.
 </td>
</tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-function.pg-escape-bytea-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>pg_escape_bytea()</strong></span></strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">// Connexion à la base de données<br /></span><span style="color: #0000BB">$dbconn </span><span style="color: #007700">= </span><span style="color: #0000BB">pg_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">'dbname=foo'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// Lecture d'un fichier binaire<br /></span><span style="color: #0000BB">$data </span><span style="color: #007700">= </span><span style="color: #0000BB">file_get_contents</span><span style="color: #007700">(</span><span style="color: #DD0000">'image1.jpg'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// Échappement des données binaires<br /></span><span style="color: #0000BB">$escaped </span><span style="color: #007700">= </span><span style="color: #0000BB">pg_escape_bytea</span><span style="color: #007700">(</span><span style="color: #0000BB">$data</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// Insertion dans la base de données<br /></span><span style="color: #0000BB">pg_query</span><span style="color: #007700">(</span><span style="color: #DD0000">"INSERT INTO gallery (name, data) VALUES ('Pine trees', '</span><span style="color: #007700">{</span><span style="color: #0000BB">$escaped</span><span style="color: #007700">}</span><span style="color: #DD0000">')"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.pg-escape-bytea-seealso">
  <h3 class="title">Voir aussi</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.pg-unescape-bytea.php" class="function" rel="rdfs-seeAlso">pg_unescape_bytea()</a> - Supprime la protection d'une cha&icirc;ne de type bytea</span></li>
    <li><span class="function"><a href="function.pg-escape-string.php" class="function" rel="rdfs-seeAlso">pg_escape_string()</a> - Prot&egrave;ge une cha&icirc;ne de caract&egrave;res pour une requ&ecirc;te SQL</span></li>
   </ul>
  </p>
 </div>

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