function to get data from db