import MySQLdb
import time
try:
db = MySQLdb.connect(host="", #your host, usually localhost
user="", #your username
passwd="", #your password
db="") #name of the data base
cur = db.cursor()
except mysql.connector.Error as err:
print("Something went wrong: {}".format(err))
SQL = "INSERT INTO TBL_PYTest (Time) VALUES (%s)"
Count = 0
while Count < 5:
UTime = int(time.time())
print UTime
cur.execute(SQL, (UTime))
time.sleep(5)
Count = Count + 1
print Count
Why isn't this working? its printing correctly but the database stays empty. Ive checked the DB and it seems fine All the details are correct
asked Oct 9, 2014 at 9:30
SteamPunk_Devil
1611 silver badge8 bronze badges
1 Answer 1
You would need to commit your transaction , or set autocommit as True.
answered Oct 9, 2014 at 9:31
DhruvPathak
43.4k17 gold badges125 silver badges180 bronze badges
Sign up to request clarification or add additional context in comments.
1 Comment
SteamPunk_Devil
Thanks that fixed it for anyone else having this problem look here: dev.mysql.com/doc/connector-python/en/…
default