added open and close functions into database.cpp