<?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.getattribute.php',
    1 => 'PDO::getAttribute',
    2 => 'R&eacute;cup&egrave;re un attribut d\'une connexion &agrave; une base de donn&eacute;es',
  ),
  'up' => 
  array (
    0 => 'class.pdo.php',
    1 => 'PDO',
  ),
  'prev' => 
  array (
    0 => 'pdo.exec.php',
    1 => 'PDO::exec',
  ),
  'next' => 
  array (
    0 => 'pdo.getavailabledrivers.php',
    1 => 'PDO::getAvailableDrivers',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'fr',
    'path' => 'reference/pdo/pdo/getattribute.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="pdo.getattribute" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">PDO::getAttribute</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.1.0, PHP 7, PHP 8, PECL pdo &gt;= 0.2.0)</p><p class="refpurpose"><span class="refname">PDO::getAttribute</span> &mdash; <span class="dc-title">
   Récupère un attribut d&#039;une connexion à une base de données
  </span></p>

 </div>
 <div class="refsect1 description" id="refsect1-pdo.getattribute-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>PDO::getAttribute</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$attribute</code></span>): <span class="type"><a href="language.types.mixed.php" class="type mixed">mixed</a></span></div>


  <p class="para rdfs-comment">
   Cette fonction retourne la valeur d&#039;un attribut d&#039;une connexion à une base
   de données. Pour récupérer les attributs <span class="classname"><a href="class.pdostatement.php" class="classname">PDOStatement</a></span>, se référer
   à la fonction <span class="methodname"><a href="pdostatement.getattribute.php" class="methodname">PDOStatement::getAttribute()</a></span>.
  </p>

  <p class="para">
   Il est à noter que quelques bases de données/drivers combinés ne supportent pas tous les attributs
   de connexion.
  </p>

 </div>


 <div class="refsect1 parameters" id="refsect1-pdo.getattribute-parameters">
  <h3 class="title">Liste de paramètres</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">attribute</code></dt>
     <dd>
      <p class="para">
       Une des constantes <code class="literal">PDO::ATTR_*</code>. Les attributs génériques
       qui sont appliqués aux connexions sont les suivantes :
       <ul class="simplelist">
        <li><code class="literal">PDO::ATTR_AUTOCOMMIT</code></li>
        <li><code class="literal">PDO::ATTR_CASE</code></li>
        <li><code class="literal">PDO::ATTR_CLIENT_VERSION</code></li>
        <li><code class="literal">PDO::ATTR_CONNECTION_STATUS</code></li>
        <li><code class="literal">PDO::ATTR_DRIVER_NAME</code></li>
        <li><code class="literal">PDO::ATTR_ERRMODE</code></li>
        <li><code class="literal">PDO::ATTR_ORACLE_NULLS</code></li>
        <li><code class="literal">PDO::ATTR_PERSISTENT</code></li>
        <li><code class="literal">PDO::ATTR_PREFETCH</code></li>
        <li><code class="literal">PDO::ATTR_SERVER_INFO</code></li>
        <li><code class="literal">PDO::ATTR_SERVER_VERSION</code></li>
        <li><code class="literal">PDO::ATTR_TIMEOUT</code></li>
       </ul>
      </p>
      <span class="simpara">
       Certains pilotes peuvent faire usage d&#039;attributs supplémentaires spécifiques au pilote.
       Il est à noter que les attributs spécifiques au pilote <em>ne doivent pas</em>
       être utilisés avec d&#039;autres pilotes.
      </span>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-pdo.getattribute-returnvalues">
  <h3 class="title">Valeurs de retour</h3>
  <p class="para">
   Un appel réussi retourne la valeur de l&#039;attribut PDO demandé.
   Un appel qui a échoué retourne la valeur <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong>.
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-pdo.getattribute-errors">
  <h3 class="title">Erreurs / Exceptions</h3>
  <p class="para">
   La méthode <span class="methodname"><strong>PDO::getAttribute()</strong></span> peut générer une exception <span class="exceptionname"><a href="class.pdoexception.php" class="exceptionname">PDOException</a></span>
   lorsque le pilote sous-jacent ne prend pas en charge l&#039;<code class="parameter">attribute</code> demandé.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-pdo.getattribute-examples">
  <h3 class="title">Exemples</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Exemple #1 Récupération des attributs de connexion à une base de données</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">'odbc:sample'</span><span style="color: #007700">, </span><span style="color: #DD0000">'db2inst1'</span><span style="color: #007700">, </span><span style="color: #DD0000">'ibmdb2'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$attributes </span><span style="color: #007700">= array(<br /></span><span style="color: #DD0000">"AUTOCOMMIT"</span><span style="color: #007700">, </span><span style="color: #DD0000">"ERRMODE"</span><span style="color: #007700">, </span><span style="color: #DD0000">"CASE"</span><span style="color: #007700">, </span><span style="color: #DD0000">"CLIENT_VERSION"</span><span style="color: #007700">, </span><span style="color: #DD0000">"CONNECTION_STATUS"</span><span style="color: #007700">,<br /></span><span style="color: #DD0000">"ORACLE_NULLS"</span><span style="color: #007700">, </span><span style="color: #DD0000">"PERSISTENT"</span><span style="color: #007700">, </span><span style="color: #DD0000">"PREFETCH"</span><span style="color: #007700">, </span><span style="color: #DD0000">"SERVER_INFO"</span><span style="color: #007700">, </span><span style="color: #DD0000">"SERVER_VERSION"</span><span style="color: #007700">,<br /></span><span style="color: #DD0000">"TIMEOUT"<br /></span><span style="color: #007700">);<br /><br />foreach (</span><span style="color: #0000BB">$attributes </span><span style="color: #007700">as </span><span style="color: #0000BB">$val</span><span style="color: #007700">) {<br />   echo </span><span style="color: #DD0000">"PDO::ATTR_</span><span style="color: #0000BB">$val</span><span style="color: #DD0000">: "</span><span style="color: #007700">;<br />   echo </span><span style="color: #0000BB">$conn</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getAttribute</span><span style="color: #007700">(</span><span style="color: #0000BB">constant</span><span style="color: #007700">(</span><span style="color: #DD0000">"PDO::ATTR_</span><span style="color: #0000BB">$val</span><span style="color: #DD0000">"</span><span style="color: #007700">)) . </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

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


 <div class="refsect1 seealso" id="refsect1-pdo.getattribute-seealso">
  <h3 class="title">Voir aussi</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="methodname"><a href="pdo.setattribute.php" class="methodname" rel="rdfs-seeAlso">PDO::setAttribute()</a> - Configure un attribut PDO</span></li>
    <li><span class="methodname"><a href="pdostatement.getattribute.php" class="methodname" rel="rdfs-seeAlso">PDOStatement::getAttribute()</a> - R&eacute;cup&egrave;re un attribut de requ&ecirc;te</span></li>
    <li><span class="methodname"><a href="pdostatement.setattribute.php" class="methodname" rel="rdfs-seeAlso">PDOStatement::setAttribute()</a> - D&eacute;finit un attribut de requ&ecirc;te</span></li>
   </ul>
  </p>
 </div>

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