depends_on only controls the build and startup order for the services.
Your actual issue is more likely that you are using the wrong address from your web application to your database. I see that you have not defined any networks, so you are using the
default network created for your application by
docker-compose. This will publish each service by name on the default network's DNS.
So, your web application should probably be using
db:3306 as the database address, not
127.0.0.1:3306 as indicated in the error message.