Source of: /manual/en/pdo.getattribute.php
<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/class.pdo.inc";
$setup = array (
'home' =>
array (
0 => 'index.php',
1 => 'PHP Manual',
),
'head' =>
array (
0 => 'UTF-8',
1 => 'en',
),
'this' =>
array (
0 => 'pdo.getattribute.php',
1 => 'PDO::getAttribute',
),
'up' =>
array (
0 => 'class.pdo.php',
1 => 'The PDO class',
),
'prev' =>
array (
0 => 'pdo.exec.php',
1 => 'PDO::exec',
),
'next' =>
array (
0 => 'pdo.getavailabledrivers.php',
1 => 'PDO::getAvailableDrivers',
),
);
$setup["toc"] = $TOC;
$setup["parents"] = $PARENTS;
manual_setup($setup);
manual_header();
?>
<div id="pdo.getattribute" class="refentry">
<div class="refnamediv">
<h1 class="refname">PDO::getAttribute</h1>
<p class="verinfo">(PHP 5 >= 5.1.0, PECL pdo >= 0.2.0)</p><p class="refpurpose"><span class="refname">PDO::getAttribute</span> — <span class="dc-title">
Retrieve a database connection attribute
</span></p>
</div>
<a name="pdo.getattribute.description"></a><div class="refsect1 description">
<h3 class="title">Description</h3>
<div class="methodsynopsis dc-description">
<span class="type"><a href="language.pseudo-types.php#language.types.mixed" class="type mixed">mixed</a></span> <span class="methodname"><b>PDO::getAttribute</b></span>
( <span class="methodparam"><span class="type">int</span> <tt class="parameter">$attribute</tt></span>
)</div>
<p class="para rdfs-comment">
This function returns the value of a database connection attribute. To
retrieve PDOStatement attributes, refer to
<a href="pdostatement.getattribute.php" class="function">PDOStatement::getAttribute()</a>.
</p>
<p class="para">
Note that some database/driver combinations may not support all of the
database connection attributes.
</p>
</div>
<a name="pdo.getattribute.parameters"></a><div class="refsect1 parameters">
<h3 class="title">Parameters</h3>
<p class="para">
</p><dl>
<dt class="varlistentry">
<span class="term"><i><tt class="parameter">attribute</tt></i>
</span>
</dt><dd class="listitem">
<p class="para">
One of the <i>PDO::ATTR_*</i> constants. The constants that
apply to database connections are as follows:
</p><ul class="simplelist">
<li class="member"><i>PDO::ATTR_AUTOCOMMIT</i></li>
<li class="member"><i>PDO::ATTR_CASE</i></li>
<li class="member"><i>PDO::ATTR_CLIENT_VERSION</i></li>
<li class="member"><i>PDO::ATTR_CONNECTION_STATUS</i></li>
<li class="member"><i>PDO::ATTR_DRIVER_NAME</i></li>
<li class="member"><i>PDO::ATTR_ERRMODE</i></li>
<li class="member"><i>PDO::ATTR_ORACLE_NULLS</i></li>
<li class="member"><i>PDO::ATTR_PERSISTENT</i></li>
<li class="member"><i>PDO::ATTR_PREFETCH</i></li>
<li class="member"><i>PDO::ATTR_SERVER_INFO</i></li>
<li class="member"><i>PDO::ATTR_SERVER_VERSION</i></li>
<li class="member"><i>PDO::ATTR_TIMEOUT</i></li>
</ul><p>
</p>
</dd>
</dl>
<p>
</p>
</div>
<a name="pdo.getattribute.returnvalues"></a><div class="refsect1 returnvalues">
<h3 class="title">Return Values</h3>
<p class="para">
A successful call returns the value of the requested PDO attribute.
An unsuccessful call returns <i>null</i>.
</p>
</div>
<a name="pdo.getattribute.examples"></a><div class="refsect1 examples">
<h3 class="title">Examples</h3>
<p class="para">
</p><div class="example">
<p><b>Example #1 Retrieving database connection attributes</b></p>
<div class="example-contents programlisting">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB"><?php<br />$conn </span><span style="color: #007700">= new </span><span style="color: #0000BB">PDO</span><span style="color: #007700">(</span><span style="color: #DD0000">'odbc:sample'</span><span style="color: #007700">, </span><span style="color: #DD0000">'db2inst1'</span><span style="color: #007700">, </span><span style="color: #DD0000">'ibmdb2'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$attributes </span><span style="color: #007700">= array(<br /> </span><span style="color: #DD0000">"AUTOCOMMIT"</span><span style="color: #007700">, </span><span style="color: #DD0000">"ERRMODE"</span><span style="color: #007700">, </span><span style="color: #DD0000">"CASE"</span><span style="color: #007700">, </span><span style="color: #DD0000">"CLIENT_VERSION"</span><span style="color: #007700">, </span><span style="color: #DD0000">"CONNECTION_STATUS"</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">"ORACLE_NULLS"</span><span style="color: #007700">, </span><span style="color: #DD0000">"PERSISTENT"</span><span style="color: #007700">, </span><span style="color: #DD0000">"PREFETCH"</span><span style="color: #007700">, </span><span style="color: #DD0000">"SERVER_INFO"</span><span style="color: #007700">, </span><span style="color: #DD0000">"SERVER_VERSION"</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">"TIMEOUT"<br /></span><span style="color: #007700">);<br /><br />foreach (</span><span style="color: #0000BB">$attributes </span><span style="color: #007700">as </span><span style="color: #0000BB">$val</span><span style="color: #007700">) {<br /> echo </span><span style="color: #DD0000">"PDO::ATTR_</span><span style="color: #0000BB">$val</span><span style="color: #DD0000">: "</span><span style="color: #007700">;<br /> echo </span><span style="color: #0000BB">$conn</span><span style="color: #007700">-></span><span style="color: #0000BB">getAttribute</span><span style="color: #007700">(</span><span style="color: #0000BB">constant</span><span style="color: #007700">(</span><span style="color: #DD0000">"PDO::ATTR_</span><span style="color: #0000BB">$val</span><span style="color: #DD0000">"</span><span style="color: #007700">)) . </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?></span>
</span>
</code></div>
</div>
</div><p>
</p>
</div>
<a name="pdo.getattribute.seealso"></a><div class="refsect1 seealso">
<h3 class="title">See Also</h3>
<p class="para">
</p><ul class="simplelist">
<li class="member"><a href="pdo.setattribute.php" class="function" rel="rdfs-seeAlso">PDO::setAttribute()</a> - Set an attribute</li>
<li class="member"><a href="pdostatement.getattribute.php" class="function" rel="rdfs-seeAlso">PDOStatement::getAttribute()</a> - Retrieve a statement attribute</li>
<li class="member"><a href="pdostatement.setattribute.php" class="function" rel="rdfs-seeAlso">PDOStatement::setAttribute()</a> - Set a statement attribute</li>
</ul><p>
</p>
</div>
</div><?php manual_footer(); ?>