I have seen many people saying that it's not good to connect a mobile app directly to the database, but to have a web service doing it. So my questions are:
Why do I need a web service (middle layer) to connect a mobile app to the database (eg.: SQLite, Firebase) instead of connecting it directly from my iOS / Android application?
Why do I need an extra layer like in PHP or Java for web to make this connection? Is it for performance purpose? Or security? Or anything else?
How do these layers work?