Update methods from newer versions of Flask

Using the new _app_ctx_stack from flask 0.9.x and above would allow to connect to the database outside a request using:
```python
mysql = MySQL()
...
with app.app_context():
    cur = mysql.get_db().cursor()
    ...
```