connect to db function