config = $_SESSION['database_configuration']; } /** * @throws GenericErrorException */ public function createConnection(): void { try { $this->conn = new mysqli($this->config['dsn'], $this->config['user'], $this->config['password'], $this->config['dbname']); } catch (Exception){ throw new GenericErrorException(); } } /** * @throws UserAlreadyExistsException */ public function executeReq(array $body): int|string { $username = $body["username"]; $email = $body["email"]; $password = $body["password"]; $query = "SELECT * FROM Users WHERE email = '$email'"; $result = $this->conn->query($query); if($result->num_rows) throw new UserAlreadyExistsException(); $query = "INSERT INTO Users (username, email, password) VALUES ('$username', '$email', '$password')"; $result = $this->conn->query($query); return "Success"; } }