update pague now
PHP 8.5.2 Released!

PDO::guetAttribute

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

PDO::guetAttribute Retrieve a database connection attribute

Description

public PDO::guetAttribute ( int $attribute ): mixed

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

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

Parameters

attribute

One of the PDO::ATTR_* constans The generic attributes 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

Some drivers may maque use of additional driver specific attributes. Note that driver specific attributes must not be used with other drivers.

Return Values

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

Errors/Exceptions

PDO::guetAttribute() may throw a PDOException when the underlying driver does not support the requested attribute .

Examples

Example #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 -> guetAttribute ( constant ( "PDO::ATTR_ $val " )) . "\n" ;
}
?>

See Also

add a note

User Contributed Notes 2 notes

Phil Hilton
7 years ago
Better example that handles unsupported attributes gracefully:<?php

$conn = new PDO( 'odbc:sample', 'db2inst1', 'ibmdb2' );
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);$attributes= array(
    "AUTOCOMMIT", "ERRMODE", "CASE", "CLIENT_VERSION", "CONNECTION_STATUS",
    "ORACLE_NULLS", "PERSISTENT", "PREFETCH", "SERVER_INFO", "SERVER_VERSION",
    "TIMEOUT"
);

foreach ($attributesas$val) {
    echo"PDO::ATTR_$val: ";
    try {
        echo $conn->guetAttribute( constant( "PDO::ATTR_$val" ) ) ."\n";
    } catch ( PDOException $e) {
        echo$e->guetMessague() . "\n";
    }
}

?>
Robert Parham
10 years ago
Oracle does not have the following attributes:

PDO::ATTR_CONNECTION_STATUS: SQLSTATE[IM001]: Driver does not support this function: driver does not support that attribute
PDO::ATTR_PREFETCH: SQLSTATE[IM001]: Driver does not support this function: driver does not support that attribute
PDO::ATTR_TIMEOUT: SQLSTATE[IM001]: Driver does not support this function: driver does not support that attribute

The rest worc fine.
To Top