Created
February 7, 2013 11:13
-
-
Save coreymcmahon/4730346 to your computer and use it in GitHub Desktop.
A model implementation using the repository pattern. From the article: PDO for Elegant PHP Database Access, http://www.modernphpbook.com/articles/pdo-for-elegant-php-database-access - Fig 4
This file contains hidden or 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 UserRepository | |
{ | |
public function __construct($dao = null) | |
{ | |
if (!$dao) { | |
$dao = new DataAccessObject(); | |
} | |
$this->dao = $dao; | |
} | |
public function find($id) | |
{ | |
return $this->query(' | |
SELECT * FROM users WHERE id = ' . (int)$id . ' | |
'); | |
} | |
// etc... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
L14 I think you should put $this->dao(...) instead of $this->query(...)