src/Auth.php
public function get($username) {


        if(is_numeric($username)) {
            $key = 'id';
        }
        else {
            $key = 'username';
        }

        $query = sprintf(self::SELECT_ALL,
            $this->params['table'],
            $this->params[$key],
            $this->pdo->quote($username));

        $stmt = $this->pdo->query($query);

		if(!$stmt) {
			$error = $this->pdo->errorInfo();
			
			throw new \Exception($error[2]);
		}
		
        if($user = $stmt->fetch(PDO::FETCH_ASSOC)) {
            return $user;
        }
        else {
            throw new UserException('User not found', 404);
        }
    }
public function get($username) {


        if(is_numeric($username)) {
            $key = 'id';
        }
        else {
            $key = 'username';
        }

        $query = sprintf(self::SELECT_ALL,
            $this->params['table'],
            $this->params[$key],
            $this->pdo->quote($username));

        $stmt = $this->pdo->query($query);

		if(!$stmt) {
			$error = $this->pdo->errorInfo();
			
			throw new \Exception($error[2]);
		}
		
        if($user = $stmt->fetch(PDO::FETCH_ASSOC)) {
            return $user;
        }
        else {
            throw new UserException('User not found', 404);
        }
    }
public function get ( $ username ) { if ( is_numeric ( $ username ) ) { $ key = 'id' ; } else { $ key = 'username' ; } $ query = sprintf ( self :: SELECT_ALL , $ this -> params [ 'table' ] , $ this -> params [ $ key ] , $ this -> pdo -> quote ( $ username ) ) ; $ stmt = $ this -> pdo -> query ( $ query ) ; if ( ! $ stmt ) { $ error = $ this -> pdo -> errorInfo ( ) ; throw new \ Exception ( $ error [ 2 ] ) ; } if ( $ user = $ stmt -> fetch ( PDO :: FETCH_ASSOC ) ) { return $ user ; } else { throw new UserException ( 'User not found' , 404 ) ; } }
Retrieves a user from the database
@param $username username
@return array user data
@throws UserException
@throws Exception
Retrieves a user from the database