Access Database in a Middleware

Thank you for your feedback and your recommendations, I will correct all that.