Skip to content

Instantly share code, notes, and snippets.

@coreymcmahon
Created February 7, 2013 11:13
Show Gist options
  • Save coreymcmahon/4730346 to your computer and use it in GitHub Desktop.
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
<?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...
}
@cherifGsoul
Copy link

L14 I think you should put $this->dao(...) instead of $this->query(...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment