2
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

1 Answer 1

3

You would need to commit your transaction , or set autocommit as True.

answered Oct 9, 2014 at 9:31
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks that fixed it for anyone else having this problem look here: dev.mysql.com/doc/connector-python/en/…

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.