tags:

views:

19

answers:

0

Is there a way to extract the DSN from a PDO object after it has been created? I have a rather tricky refactoring job to do and so far my best candidate solution may necessitate getting this info out of a PDO constructed elsewhere.

For example:

<?php
$pdo = new PDO("sqlite::memory");
$otherClass = new OtherClass();
$otherClass->setDbConnection($pdo);

// otherClass setDbConnection
function setDbConnection($db) {
    if ($db instanceof PDO) {
        // does not work as this attribute doesn't exist
        $this->dsn = $db->getAttribute(PDO::ATTR_DSN);
    }
    //other stuff
}

Forgetting the contrived example, is this possible to do through another means?