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

1 Answer 1

3

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

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/…

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.