PHP Data Objects (PDO) Step By Step Tutorial - Part 16: At several previous tutorial about connection attributes, we talk how to set attributes. Now, we talk about how to get value from connection attributes. We can use getAttribute(). Look this example:
PDO:ATTR_DRIVER_NAME: It returns the name of the underlying database driver.
<?php
// configuration
$dbtype = "sqlite";
$dbhost = "localhost";
$dbname = "test";
$dbuser = "root";
$dbpass = "admin";
// database connection
$conn = new PDO("mysql:host=$dbhost;dbname=$dbname",$dbuser,$dbpass, array(PDO::ATTR_PERSISTENT => true));
echo $conn->getAttribute(PDO::ATTR_DRIVER_NAME);
// result: mysql
?>
Else example:
<?php
// configuration
$dbtype = "sqlite";
$dbhost = "localhost";
$dbname = "test";
$dbuser = "root";
$dbpass = "admin";
// database connection
$conn = new PDO("mysql:host=$dbhost;dbname=$dbname",$dbuser,$dbpass, array(PDO::ATTR_PERSISTENT => true));
echo $conn->getAttribute(PDO::ATTR_DRIVER_NAME);
echo "<br>";
echo $conn->getAttribute(PDO::ATTR_CLIENT_VERSION);
echo "<br>";
echo $conn->getAttribute(PDO::ATTR_SERVER_VERSION);
?>