Advertisement
Guest User

Untitled

a guest
Jul 19th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. <?php
  2.  
  3. require_once(__DIR__ . '/MySqlDb.php');
  4. require_once(__DIR__ . '/../model/User.php');
  5.  
  6. class ExampleSiteDb extends MySqlDb {
  7. private static $shared = null;
  8.  
  9. public static function shared(): ExampleSiteDb {
  10. if(self::$shared == null){
  11. self::$shared = new ExampleSiteDb();
  12. }
  13.  
  14. return self::$shared;
  15. }
  16.  
  17. /*---- Users Examples ----------------------------------------------------------------*/
  18.  
  19. /**
  20. * Returns array of User objects, directly cast from DB query
  21. */
  22. public function getUsers(): array {
  23. return $this->query(
  24. "SELECT * FROM users",
  25. [],
  26. User::class
  27. );
  28. }
  29.  
  30. /**
  31. * Returns User object or null, directly cast from DB query
  32. */
  33. public function getUserById($id): ?User {
  34. return $this->querySingle(
  35. "SELECT * FROM users WHERE user_id=?",
  36. [$id],
  37. User::class);
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement