Advertisement
Guest User

Untitled

a guest
Jan 15th, 2017
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.00 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. import MySQLdb
  4. import configdb # <- File that contains the database parameters.
  5.  
  6. # -----Commented code
  7. #dbserver = "192.168.1.101"
  8. #dbuser = "pi"
  9. #dbpass ="test"
  10. #dbdb= "sensortest"
  11. # -----------
  12.  
  13.  
  14. def main():
  15.     print(configdb.dbhost) # <- to test to see if the values are coming back.
  16.     print(configdb.dbuser) # <- to test to see if the values are coming back.
  17.     # Open database connection
  18.     db = MySQLdb.connect(configdb.dbhost,configdb.dbuser,configdb.dbpasswd,configdb.dbname) #  <- this doesn't work
  19.     #db = MySQLdb.connect(dbserver,dbuser,dbpass,dbdb) # This works.
  20.     # prepare a cursor object using cursor() method
  21.     cursor = db.cursor()
  22.    
  23.     # execute SQL query using execute() method.
  24.     cursor.execute("SELECT VERSION()")
  25.    
  26.     # Fetch a single row using fetchone() method.
  27.     data = cursor.fetchone()
  28.    
  29.     print "Database version : %s " % data
  30.    
  31.     # disconnect from server
  32.     db.close()
  33. if __name__ == '__main__':
  34.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement