[doc-en] master: PDO::getAttribute(): document which attributes every driver supports (#6076)
| From: | Asish Kumar via GitHub | Date: | Sat, 14 Nov 2026 12:39:26 +0000 |
| Subject: | [doc-en] master: PDO::getAttribute(): document which attributes every driver supports (#6076) | ||
| Groups: | php.doc.cvs | ||
| Request: | Send a blank email to doc-cvs+get-23953@lists.php.net to get a copy of this message | ||
Author: Asish Kumar (officialasishkumar)
Committer: GitHub (web-flow)
Pusher: kamil-tekiela
Date: 2026-11-14T12:39:23Z
Commit: https://github.com/php/doc-en/commit/ea010c6c957f8fdd64e1d622ab5fbe584cf3d231
Raw diff: https://github.com/php/doc-en/commit/ea010c6c957f8fdd64e1d622ab5fbe584cf3d231.diff
PDO::getAttribute(): document which attributes every driver supports (#6076)
Changed paths:
M reference/pdo/pdo/getattribute.xml
Diff:
diff --git a/reference/pdo/pdo/getattribute.xml b/reference/pdo/pdo/getattribute.xml
index d34db7d79821..4ddfb01c86bc 100644
--- a/reference/pdo/pdo/getattribute.xml
+++ b/reference/pdo/pdo/getattribute.xml
@@ -20,10 +20,11 @@
<methodname>PDOStatement::getAttribute</methodname>.
</para>
- <para>
- Note that some database/driver combinations may not support all of the
- database connection attributes.
- </para>
+ <simpara>
+ Only the generic attributes listed below can be retrieved with every
+ driver. Whether any other attribute can be retrieved depends on the
+ driver.
+ </simpara>
</refsect1>
@@ -35,9 +36,10 @@
<term><parameter>attribute</parameter></term>
<listitem>
<para>
- One of the
<constant>PDO::ATTR_<replaceable>*</replaceable></constant> constants. The
generic attributes that
- apply to database connections are as follows:
- <simplelist>
+ One of the
<constant>PDO::ATTR_<replaceable>*</replaceable></constant> constants.
+ The following generic attributes are handled by PDO itself
+ and can be retrieved with every driver:
+ <simplelist>
<member><constant>PDO::ATTR_CASE</constant></member>
<member><constant>PDO::ATTR_DEFAULT_FETCH_MODE</constant></member>
<member><constant>PDO::ATTR_DRIVER_NAME</constant></member>
@@ -46,10 +48,19 @@
<member><constant>PDO::ATTR_PERSISTENT</constant></member>
<member><constant>PDO::ATTR_STATEMENT_CLASS</constant></member>
<member><constant>PDO::ATTR_STRINGIFY_FETCHES</constant></member>
- </simplelist>
+ </simplelist>
</para>
<simpara>
- Some drivers may make use of additional driver specific attributes.
+ All other attributes are handled by the driver.
+ Which of them can be retrieved varies from driver to driver.
+ This includes generic attributes such as
+ <constant>PDO::ATTR_AUTOCOMMIT</constant>,
+ <constant>PDO::ATTR_CLIENT_VERSION</constant>,
+ <constant>PDO::ATTR_CONNECTION_STATUS</constant>,
+ <constant>PDO::ATTR_SERVER_INFO</constant>,
+ <constant>PDO::ATTR_SERVER_VERSION</constant> and
+ <constant>PDO::ATTR_TIMEOUT</constant>,
+ as well as driver specific attributes.
Note that driver specific attributes <emphasis>must not</emphasis> be used
with other drivers.
</simpara>
@@ -62,17 +73,21 @@
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<simpara>
- A successful call returns the value of the requested PDO attribute.
- An unsuccessful call returns &null;.
+ Returns the value of the requested attribute, or &false; on failure.
+ </simpara>
+ <simpara>
+ The value of some attributes, such as
+ <constant>PDO::ATTR_PERSISTENT</constant>, can itself be &false;,
+ so a &false; return value does not always indicate a failure.
</simpara>
</refsect1>
<refsect1 role="errors">
&reftitle.errors;
- <para>
+ <simpara>
<methodname>PDO::getAttribute</methodname> may throw a
<exceptionname>PDOException</exceptionname>
when the underlying driver does not support the requested
<parameter>attribute</parameter>.
- </para>
+ </simpara>
</refsect1>
<refsect1 role="changelog">
@@ -117,28 +132,38 @@
<programlisting role="php">
<![CDATA[
<?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"
-);
+$pdo = new PDO('sqlite::memory:');
+
+$attributes = [
+ 'DRIVER_NAME', 'ERRMODE', 'CASE', 'ORACLE_NULLS',
'PERSISTENT',
+ 'CLIENT_VERSION', 'SERVER_VERSION', 'AUTOCOMMIT',
'TIMEOUT',
+];
-foreach ($attributes as $val) {
- echo "PDO::ATTR_$val: ";
- echo $conn->getAttribute(constant("PDO::ATTR_$val")) . "\n";
+foreach ($attributes as $name) {
+ try {
+ $value = $pdo->getAttribute(constant("PDO::ATTR_$name"));
+ echo "PDO::ATTR_$name: ", var_export($value, true), "\n";
+ } catch (PDOException $e) {
+ echo "PDO::ATTR_$name: ", $e->getMessage(), "\n";
+ }
}
?>
]]>
</programlisting>
- <!--
- &example.outputs;
+ &example.outputs.similar;
<screen>
<![CDATA[
-Use the PEAR Coding Standards
+PDO::ATTR_DRIVER_NAME: 'sqlite'
+PDO::ATTR_ERRMODE: 2
+PDO::ATTR_CASE: 0
+PDO::ATTR_ORACLE_NULLS: 0
+PDO::ATTR_PERSISTENT: false
+PDO::ATTR_CLIENT_VERSION: '3.46.1'
+PDO::ATTR_SERVER_VERSION: '3.46.1'
+PDO::ATTR_AUTOCOMMIT: 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
]]>
</screen>
- -->
</example>
</para>
</refsect1>