Guest User

Untitled

a guest
Oct 18th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.83 KB | None | 0 0
  1. class User {
  2.   function save() {
  3.     DB::exec('INSERT INTO User (username, password)', ['username' => $this->username, 'password' => $password);
  4.     $this->id = PDO::lastInsertId();
  5.   }
  6.  
  7.   function load($id) {
  8.     DB::exec('SELECT * FROM User WHERE id = :id', ['id' => $id]);
  9.     $data = DB::fetch();
  10.     $this->id = $data['id'];
  11.     $this->username = $data['id'];
  12.     $this->password = $data['password'];
  13.   }
  14.  
  15.   static function find($id) {
  16.     return (new User())->load($id);
  17.   }
  18.  
  19.   static function login($username, $password) {
  20.     DB::exec('SELECT FROM User WHERE username = :username, password = PASSWORD(:password)', ['username' => $username, 'password' => $password]);
  21.     $user = DB::fetch();
  22.     if($user)
  23.       $_SESSION['userId'] = $user->id;
  24.   }
  25.  
  26.   static function logout() {
  27.       unset($_SESSION['userId']);
  28.   }
  29. };
Add Comment
Please, Sign In to add comment