Created
November 4, 2010 19:56
-
-
Save scottmac/663080 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class DatabaseStatementBase extends PDOStatement { | |
public $dbh; | |
protected function __construct($dbh) { | |
$this->dbh = $dbh; | |
$this->setFetchMode(PDO::FETCH_OBJ); | |
} | |
} | |
class DatabaseConnection extends PDO { | |
function __construct($dsn, $username, $password, $driver_options = array()) | |
{ | |
parent::__construct($dsn, $username, $password, $driver_options); | |
$this->setAttribute(PDO::ATTR_STATEMENT_CLASS, | |
array('DatabaseStatementBase', array($this))); | |
} | |
} | |
$pdo = new DatabaseConnection('sqlite::memory:', '', ''); | |
$pdo->exec('CREATE TABLE foo (bar STRING)'); | |
$pdo->exec("INSERT INTO foo VALUES ('ABC')"); | |
$result = $pdo->query("SELECT * FROM foo"); | |
foreach ($result as $row) { | |
var_dump($row); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment