title: saving sensor data raspberry pi to data base
body: <p>I'm currently working with raspberry pi and using DHT11 to read temperature and humidity values every second. I have to save these values into a database in real time.
  here's my code that showing sensor data every second, i don't know how and where do i insert lines of connection to database.</p>
  
  <pre><code>import RPi.GPIO as GPIO
  import dht11
  import time
  import datetime
  
  
  
  # initialize GPIO
  GPIO.setwarnings(False)
  GPIO.setmode(GPIO.BCM)
  GPIO.cleanup()
  
  # read data using pin 7
  instance = dht11.DHT11(pin=4)
  
  
  while True:
  
  
  
      result = instance.read()
      if result.is_valid():
          print("Last valid input: " + str(datetime.datetime.now()))
          print("Temperature: %d C" % result.temperature)
          #print("Temperature: %d F" % ((result.temperature * 9/5) + 32))
          print("Humidity: %d %%" % result.humidity)
  
  time.sleep(1)
  </code></pre>