Php

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:
 
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?
You already invited:

If you wanna answer this question please Login or Register