Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- PDO in class not executing
- public function loginUser(PDO $db, $email, $password)
- {
- $this->_db = $db;
- $this->_email = $email;
- $this->_password = $password;
- $user = $this->_checkCredentials();
- if ($user) {
- $this->_user = $user; // store it so it can be accessed later
- return $user['id'];
- }
- return false;
- }
- protected function _checkCredentials()
- {
- $stmt = $this->_db->prepare('SELECT * FROM member WHERE email = ? AND password = ?');
- $stmt->execute(array($this->_email, $this->_password));
- if ($stmt->rowCount() > 0) {
- $user = $stmt->fetch(PDO::FETCH_ASSOC);
- return $user;
- }
- return $stmt->debugDumpParams();
- }
- $userService = new UserService();
- if ($user_id = $userService->loginUser($pdo, 'user@mail.com', 'userpass')) {
- echo 'Logged it as user id: '.$user_id;
- $userData = $userService->getUser();
- // do stuff
- } else {
- echo 'Invalid login';
- }
Add Comment
Please, Sign In to add comment