Added reconnection and replaced escaping to built in function of MySQL class