Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once(__DIR__ . '/MySqlDb.php');
- require_once(__DIR__ . '/../model/User.php');
- class ExampleSiteDb extends MySqlDb {
- private static $shared = null;
- public static function shared(): ExampleSiteDb {
- if(self::$shared == null){
- self::$shared = new ExampleSiteDb();
- }
- return self::$shared;
- }
- /*---- Users Examples ----------------------------------------------------------------*/
- /**
- * Returns array of User objects, directly cast from DB query
- */
- public function getUsers(): array {
- return $this->query(
- "SELECT * FROM users",
- [],
- User::class
- );
- }
- /**
- * Returns User object or null, directly cast from DB query
- */
- public function getUserById($id): ?User {
- return $this->querySingle(
- "SELECT * FROM users WHERE user_id=?",
- [$id],
- User::class);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement