Connect to database and add some functions