Added database error checking function
Added error checking to control database functions