(PHP 5 >= 5.1.0, PECL pdo >= 0.2.0)
PDO::getAttribute — 取回一个数据库连接的属性
此函数(方法)返回一个数据库连接的属性值。 取回 PDOStatement 属性,请参阅 PDOStatement::getAttribute()。
注意有些数据库/驱动可能不支持所有的数据库连接属性。
attribute
PDO::ATTR_* 常量中的一个。下列为应用到数据库连接中的常量:
成功调用则返回请求的 PDO 属性值。不成功则返回 null。
Example #1 取回数据库连接属性
<?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";
}
?>
peter dot hopfgartner at r3-gis dot com (2009-09-08 01:44:16)
The Oracle driver seems to not support PDO::getAttribute():
ociPHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[IM001]: Driver does not support this function: driver does not support getting attributes' in ...
Tim (2007-01-11 08:20:00)
If you want to retreive the Database type connection you can use the constant:
ATTR_DRIVER_NAME
$pdo_connection->getAttribute(constant("PDO::ATTR_DRIVER_NAME"))
Although i do not know if all drivers support this contant