Code for connecting to the database and constructing the tables