Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. import MySQLdb
  2.  
  3. function init():
  4. db = self.connectlaDB()
  5. self.enregistreEnBoucle(db)
  6.  
  7. function db = connectlaDB()
  8. db = MySQLdb.connect(host="192.12122 ip du pi", # your host, usually localhost
  9. user="Sin", # your username
  10. passwd="megajonhy", # your password
  11. db="NOM DE LA DB") # name of the data base
  12. return db
  13.  
  14.  
  15. function enregistreEnBoucle(db) :
  16.  
  17. try : # si la connexion bu, on fait pas la suite
  18.  
  19.  
  20.  
  21. while true
  22.  
  23. # you must create a Cursor object. It will let
  24. # you execute all the queries you need
  25. cur = db.cursor()
  26.  
  27. # Use all the SQL you like
  28. cur.execute("INSERT INTO TABLE VALUES('DATEHEURE','CPUMEMORY','RAMMERMORY','BITES'))
  29.  
  30. # print all the first cell of all the rows
  31. db.commit()
  32. cur.close()
  33. pause(nombre seconde entre chaque insertion dans la db)
  34.  
  35. except mysql.connector.Error as error:
  36. print 'error'
  37.  
  38. finally:
  39. if (connection.is_connected()):
  40. connection.close()
  41. print("MySQL connection is closed")
  42.  
  43. function niqueLesValeurs(db):
  44. cur = db.cursor()
  45.  
  46. # Use all the SQL you like
  47. cur.execute("drop table NOMDELATABLE"))
  48.  
  49. # print all the first cell of all the rows
  50. db.commit()
  51. cur.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement