Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import MySQLdb
- import configdb # <- File that contains the database parameters.
- # -----Commented code
- #dbserver = "192.168.1.101"
- #dbuser = "pi"
- #dbpass ="test"
- #dbdb= "sensortest"
- # -----------
- def main():
- print(configdb.dbhost) # <- to test to see if the values are coming back.
- print(configdb.dbuser) # <- to test to see if the values are coming back.
- # Open database connection
- db = MySQLdb.connect(configdb.dbhost,configdb.dbuser,configdb.dbpasswd,configdb.dbname) # <- this doesn't work
- #db = MySQLdb.connect(dbserver,dbuser,dbpass,dbdb) # This works.
- # prepare a cursor object using cursor() method
- cursor = db.cursor()
- # execute SQL query using execute() method.
- cursor.execute("SELECT VERSION()")
- # Fetch a single row using fetchone() method.
- data = cursor.fetchone()
- print "Database version : %s " % data
- # disconnect from server
- db.close()
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement