add connectDB function, shamelessly nicked from dwhalstrom