Function for getting datas from the database