downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

PDO::getAvailableDrivers> <PDO::exec
Last updated: Fri, 14 Aug 2009

view this page in

PDO::getAttribute

(PHP 5 >= 5.1.0, PECL pdo >= 0.2.0)

PDO::getAttribute Récupère un attribut d'une connexion à une base de données

Description

mixed PDO::getAttribute ( int $attribute )

Cette fonction retourne la valeur d'un attribut d'une connexion à une base de données. Pour récupérer les attributs PDOStatement, référez-vous à la fonction PDOStatement::getAttribute().

Notez que quelques bases de données/drivers combinés ne supportent pas tous les attributs de connexion.

Liste de paramètres

attribute

Une des constantes PDO::ATTR_*. Les constantes qui sont appliquées aux connexions sont les suivantes :

  • PDO::ATTR_AUTOCOMMIT
  • PDO::ATTR_CASE
  • PDO::ATTR_CLIENT_VERSION
  • PDO::ATTR_CONNECTION_STATUS
  • PDO::ATTR_DRIVER_NAME
  • PDO::ATTR_ERRMODE
  • PDO::ATTR_ORACLE_NULLS
  • PDO::ATTR_PERSISTENT
  • PDO::ATTR_PREFETCH
  • PDO::ATTR_SERVER_INFO
  • PDO::ATTR_SERVER_VERSION
  • PDO::ATTR_TIMEOUT

Valeurs de retour

Un appel réussi retourne la valeur de l'attribut PDO demandé. Un appel qui a échoué retourne la valeur NULL.

Exemples

Exemple #1 Récupération des attributs de connexion à une base de données

<?php
$conn 
= new PDO('odbc:sample''db2inst1''ibmdb2');
$attributes = array(
"AUTOCOMMIT""ERRMODE""CASE""CLIENT_VERSION""CONNECTION_STATUS",
"ORACLE_NULLS""PERSISTENT""PREFETCH""SERVER_INFO""SERVER_VERSION",
"TIMEOUT"
);

foreach (
$attributes as $val) {
   echo 
"PDO::ATTR_$val: ";
   echo 
$conn->getAttribute(constant("PDO::ATTR_$val")) . "\n";
}
?>

Voir aussi



add a note add a note User Contributed Notes
PDO::getAttribute
peter dot hopfgartner at r3-gis dot com
08-Sep-2009 08:44
The Oracle driver seems to not support PDO::getAttribute():

ociPHP Fatal error:  Uncaught exception 'PDOException' with message 'SQLSTATE[IM001]: Driver does not support this function: driver does not support getting attributes' in ...
Tim
11-Jan-2007 04:20
If you want to retreive the Database type connection you can use the constant:

ATTR_DRIVER_NAME

$pdo_connection->getAttribute(constant("PDO::ATTR_DRIVER_NAME"))

Although i do not know if all drivers support this contant

PDO::getAvailableDrivers> <PDO::exec
Last updated: Fri, 14 Aug 2009
 
 
show source | credits | sitemap | contact | advertising | mirror sites