Adding database code

Fully functional code for database interaction.