SteamPunk_Devil
SteamPunk_Devil

Reputation: 161

Python Not inserting into MySQL

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

Upvotes: 2

Views: 112

Answers (1)

DhruvPathak
DhruvPathak

Reputation: 43265

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

Upvotes: 3

Related Questions