PHP Doku:: Retrieve a database connection attribute - pdo.getattribute.html

Verlauf / Chronik / History: (4) anzeigen

Sie sind hier:
Doku-StartseitePHP-HandbuchFunktionsreferenzDatenbankerweiterungenAbstraktionsebenenPHP Data ObjectsDie PDO-KlassePDO::getAttribute

Ein Service von Reinhard Neidl - Webprogrammierung.

Die PDO-Klasse

<<PDO::exec

PDO::getAvailableDrivers>>

PDO::getAttribute

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

PDO::getAttribute Retrieve a database connection attribute

Beschreibung

mixed PDO::getAttribute ( int $attribute )

This function returns the value of a database connection attribute. To retrieve PDOStatement attributes, refer to PDOStatement::getAttribute().

Note that some database/driver combinations may not support all of the database connection attributes.

Parameter-Liste

attribute

One of the PDO::ATTR_* constants. The constants that apply to database connections are as follows:

  • 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

Rückgabewerte

A successful call returns the value of the requested PDO attribute. An unsuccessful call returns null.

Beispiele

Beispiel #1 Retrieving database connection attributes

<?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";
}
?>

Siehe auch


2 BenutzerBeiträge:
- Beiträge aktualisieren...
peter dot hopfgartner at r3-gis dot com
8.09.2009 10: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.01.2007 17: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



PHP Powered Diese Seite bei php.net
The PHP manual text and comments are covered by the Creative Commons Attribution 3.0 License © the PHP Documentation Group - Impressum - mail("TO:Reinhard Neidl",...)