PDO::getAttribute
(PHP 5 >= 5.1.0, PHP 7, PHP 8, PECL pdo >= 0.2.0)
Retrieve a database connection attribute
Description
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.
Parameters
attributeOne of the
PDO::ATTR_*constants. The generic attributes that apply to database connections are as follows:PDO::ATTR_CASEPDO::ATTR_DEFAULT_FETCH_MODEPDO::ATTR_DRIVER_NAMEPDO::ATTR_ERRMODEPDO::ATTR_ORACLE_NULLSPDO::ATTR_PERSISTENTPDO::ATTR_STATEMENT_CLASSPDO::ATTR_STRINGIFY_FETCHES
Some drivers may make 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::getAttribute may throw a PDOException when the underlying driver does not support the requested attribute.
Changelog
| Version | Description |
|---|---|
| 8.4.0 | It is now possible to fetch the value of the PDO::ATTR_STRINGIFY_FETCHES attribute. |
Examples
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";
}
?>See Also
PDO::setAttributePDOStatement::getAttributePDOStatement::setAttribute