PDO::getAttribute – Retrieve a Database Connection Attribute
The article explains the PDO::getAttribute method, lists all PDO::ATTR_* constants that can be queried, describes its return behavior, and provides a PHP example demonstrating how to retrieve multiple connection attributes for debugging.
This function (method) returns the value of a PDO database connection attribute.
Parameter
attribute
One of the PDO::ATTR_* constants, such as:
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
Return value
On success, returns the requested PDO attribute value; on failure, returns null .
Example
<?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";
}
?>Laravel Tech Community
Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.