Fixing mysql connection closing