Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pymysql.cursors
- from time import gmtime, strftime
- print ("Jungiamasi...")
- connection = pymysql.connect(host='localhost',
- user='root',
- password='',
- db='test',
- cursorclass=pymysql.cursors.DictCursor)
- print("Prisijungta.")
- temperatura = "21.5"
- dregme = "28"
- laikas = strftime("%Y-%m-%d", gmtime())
- try:
- with connection.cursor() as cursor:
- sql = "INSERT INTO `orai`(temperatura, dregme, datetime) VALUES (%s, %s, %s)"
- cursor.execute(sql, (temperatura, dregme, laikas))
- connection.commit()
- with connection.cursor() as cursor:
- sql = "SELECT `temperatura`, `dregme` FROM `orai` WHERE `id`=1"
- cursor.execute(sql)
- result = cursor.fetchone()
- print(result)
- finally:
- connection.close()
- print("done")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement