I use the repository template ( http://martinfowler.com/eaaCatalog/repository.html ) to put my entire database and SQL code in a small set of classes that are responsible for translating between the database and domain objects. This allows the rest of the code to have redundant db connection code or SQL queries.
I use it as follows:
$criteria = new UserCriteria();
$criteria->active = true;
$repository->getUsers($criteria);
source
share