PDO: Getting Connection Attributes



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);

?>

Previous: PDO: Improve Performance with Persistent Connection


Series this article:
PDO: Introduction PHP Data Object
PDO: Activation PHP Data Objects Extension
PDO: Connecting Use PHP Data Object
PDO: Portable Connection to Database
PDO: Posibble Fetch Mode
PDO: Error Handling
PDO: Prepared Statement
PDO: Positional and Named Placeholders
PDO: Insert and Update Statement Use Prepared Statement
PDO: Prepared Statement and Bound Values
PDO: Working With BLOBs
PDO: Alternative Retrieve BLOB Data
PDO: Setting Connection Attributes
PDO: Error Mode Attributes
PDO: Improve Performance with Persistent Connection
PDO: Getting Connection Attributes


Tag: PHP Data Objects, PDO, dll, extension, PHP extension, attribute Category: PHP Database Post : April 20th 2008 Read: 3,887 Bookmark and Share

blog comments powered by Disqus