diff --git a/src/ExtendedPdo.php b/src/ExtendedPdo.php index 1b3ed9ca..3139817a 100644 --- a/src/ExtendedPdo.php +++ b/src/ExtendedPdo.php @@ -573,6 +573,19 @@ public function getDsn() return $this->dsn; } + /** + * + * Returns the underlying PDO connection object. + * + * @return PDO + * + */ + public function getPdo() + { + $this->connect(); + return $this->pdo; + } + /** * * Returns the profiler object. diff --git a/src/ExtendedPdoInterface.php b/src/ExtendedPdoInterface.php index 103da20d..343e4fbb 100644 --- a/src/ExtendedPdoInterface.php +++ b/src/ExtendedPdoInterface.php @@ -210,6 +210,15 @@ public function fetchValue($statement, array $values = array()); */ public function getDsn(); + /** + * + * Returns the underlying PDO connection object. + * + * @return PDO + * + */ + public function getPdo(); + /** * * Returns the profiler object. diff --git a/tests/src/AbstractExtendedPdoTest.php b/tests/src/AbstractExtendedPdoTest.php index a0eaf1b2..71ff8786 100755 --- a/tests/src/AbstractExtendedPdoTest.php +++ b/tests/src/AbstractExtendedPdoTest.php @@ -65,6 +65,8 @@ protected function insert(array $data) $this->pdo->perform($stm, $data); } + abstract public function testGetPdo(); + public function testErrorCodeAndInfo() { $actual = $this->pdo->errorCode(); diff --git a/tests/src/DecoratedPdoTest.php b/tests/src/DecoratedPdoTest.php index 7af1ca7c..182817e6 100644 --- a/tests/src/DecoratedPdoTest.php +++ b/tests/src/DecoratedPdoTest.php @@ -5,9 +5,16 @@ class DecoratedPdoTest extends AbstractExtendedPdoTest { + protected $decorated_pdo; + protected function newExtendedPdo() { - $pdo = new PDO('sqlite::memory:'); - return new ExtendedPdo($pdo); + $this->decorated_pdo = new PDO('sqlite::memory:'); + return new ExtendedPdo($this->decorated_pdo); + } + + public function testGetPdo() + { + $this->assertSame($this->decorated_pdo, $this->pdo->getPdo()); } } diff --git a/tests/src/ExtendedPdoTest.php b/tests/src/ExtendedPdoTest.php index a523f3bb..9b6e99b7 100644 --- a/tests/src/ExtendedPdoTest.php +++ b/tests/src/ExtendedPdoTest.php @@ -23,4 +23,11 @@ protected function newExtendedPdo() $attributes ); } + + public function testGetPdo() + { + $lazy_pdo = $this->pdo->getPdo(); + $this->assertInstanceOf('PDO', $lazy_pdo); + $this->assertNotSame($this->pdo, $lazy_pdo); + } }