Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import MySQLdb
- function init():
- db = self.connectlaDB()
- self.enregistreEnBoucle(db)
- function db = connectlaDB()
- db = MySQLdb.connect(host="192.12122 ip du pi", # your host, usually localhost
- user="Sin", # your username
- passwd="megajonhy", # your password
- db="NOM DE LA DB") # name of the data base
- return db
- function enregistreEnBoucle(db) :
- try : # si la connexion bu, on fait pas la suite
- while true
- # you must create a Cursor object. It will let
- # you execute all the queries you need
- cur = db.cursor()
- # Use all the SQL you like
- cur.execute("INSERT INTO TABLE VALUES('DATEHEURE','CPUMEMORY','RAMMERMORY','BITES'))
- # print all the first cell of all the rows
- db.commit()
- cur.close()
- pause(nombre seconde entre chaque insertion dans la db)
- except mysql.connector.Error as error:
- print 'error'
- finally:
- if (connection.is_connected()):
- connection.close()
- print("MySQL connection is closed")
- function niqueLesValeurs(db):
- cur = db.cursor()
- # Use all the SQL you like
- cur.execute("drop table NOMDELATABLE"))
- # print all the first cell of all the rows
- db.commit()
- cur.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement