database write function added.