Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class User {
- function save() {
- DB::exec('INSERT INTO User (username, password)', ['username' => $this->username, 'password' => $password);
- $this->id = PDO::lastInsertId();
- }
- function load($id) {
- DB::exec('SELECT * FROM User WHERE id = :id', ['id' => $id]);
- $data = DB::fetch();
- $this->id = $data['id'];
- $this->username = $data['id'];
- $this->password = $data['password'];
- }
- static function find($id) {
- return (new User())->load($id);
- }
- static function login($username, $password) {
- DB::exec('SELECT FROM User WHERE username = :username, password = PASSWORD(:password)', ['username' => $username, 'password' => $password]);
- $user = DB::fetch();
- if($user)
- $_SESSION['userId'] = $user->id;
- }
- static function logout() {
- unset($_SESSION['userId']);
- }
- };
Add Comment
Please, Sign In to add comment