Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. class User {
  2.  
  3. private $userId;
  4. private $userDAO;
  5.  
  6. public function __construct($dbh, $userId) {
  7.  
  8. $this->userId = (int) $userId;
  9. //Create the UserDAO object
  10. $this->userDAO = new UserDAO($dbh, $this);
  11.  
  12. //Get the up to date details of the user
  13. $userData = $this->userDAO->getUserData()
  14.  
  15. }
  16.  
  17. }
  18.  
  19. class UserDAO {
  20.  
  21. private $dbh;
  22. private $user;
  23.  
  24. public function __construct($dbh, $user) {
  25.  
  26. $this->dbh = $dbh;
  27. $this->user = $user;
  28.  
  29. }
  30.  
  31. public function getUserData() {
  32.  
  33. $stmt = $this->dbh->prepare("SELECT username FROM " . USERS_TABLE . " WHERE userId = :userId LIMIT 1");
  34. $stmt->bindParam(':userId', $this->user->getUserId(), PDO::PARAM_INT);
  35. $stmt->execute();
  36. return $stmt->fetch(PDO::FETCH_ASSOC);
  37.  
  38. }
  39.  
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement