/** * @param $email * @param $password * @return User|null */ public static function getUserByEmailAndPassword($email, $password) { $database = Application::getDatabase(); $sth = $database->prepare("SELECT * FROM " . self::$tableName . " WHERE email = ? AND password = ? LIMIT 1"); $sth->execute([$email, self::makePassword($password)]); $result = $sth->fetch(\PDO::FETCH_ASSOC); if (false !== $result) { return new User($result); } }
public function update() { $this->onBeforeUpdate(); $allData = $this->getAllData(); unset($allData['id']); $sets = []; foreach ($allData as $key => $value) { $sets[] = "{$key} = ?"; } $query = "UPDATE {$this->tableName} SET " . join(', ', $sets) . " WHERE id = ?"; $allData['id'] = $this->id; // add to end of list $sth = Application::getDatabase()->prepare($query); $sth->execute(array_values($allData)); return 0 === intval($sth->errorCode()); }