Hi guys, I'm trying to learn the proper (standard) OOP way of dealing with Entities and Repositories without an ORM or framework for now.
Hi guys, I'm trying to learn the proper (standard) OOP way of dealing with Entities and Repositories without an ORM or framework for now. Take the following for example:
Specifically, the UserRepository class first, that's pretty standard, yes?
class UserRepository {
private $db;
public function __construct(PDO $db)
{
$this->db = $db;
}
public function getByEmail($email) {
$stmt = $this->db->prepare('SELECT id, email, firstname FROM users WHERE email = :email) //the query
$stmt->execute(["email" => $email]);
$user = $stmt->fetch();
}
}
class UserEntity {
protected $id;
protected $email;
protected $firstName;
}
$userRepo = new UserRepository($db);
$user = $userRepo->getByEmail('[email protected]');Specifically, the UserRepository class first, that's pretty standard, yes?
No any search results
You already invited:
0 Answers