Handle re-connections

Long-term mysql connection gets close after long idle
times. Therefore, it is important to check whether or
not the conneciton is still alive and re-connect.

Signed-off-by: Martin Abente Lahaye <tch@sugarlabs.org>