Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class User {
- private $userId;
- private $userDAO;
- public function __construct($dbh, $userId) {
- $this->userId = (int) $userId;
- //Create the UserDAO object
- $this->userDAO = new UserDAO($dbh, $this);
- //Get the up to date details of the user
- $userData = $this->userDAO->getUserData()
- }
- }
- class UserDAO {
- private $dbh;
- private $user;
- public function __construct($dbh, $user) {
- $this->dbh = $dbh;
- $this->user = $user;
- }
- public function getUserData() {
- $stmt = $this->dbh->prepare("SELECT username FROM " . USERS_TABLE . " WHERE userId = :userId LIMIT 1");
- $stmt->bindParam(':userId', $this->user->getUserId(), PDO::PARAM_INT);
- $stmt->execute();
- return $stmt->fetch(PDO::FETCH_ASSOC);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement