I'm a newbie to python and i am trying to insert some data in to a mysql table .Seems the query executed with out any issues, however i don't see any record added on to the table.
Any help would be greatly appreciated.
Cheers, Aditya
connection = mysql.connector.connect(user='sandboxbeta2503', password='XXX',
host='myreleasebox.com',
database='iaas')
print ("Updating the history in bulk_notification_history")
cursor = connection.cursor()
timestamp = time.strftime("%Y-%m-%d %X")
notification_type = "Notify Inactive users"
usercount= 45
query = ("INSERT INTO iaas.bulk_notification_history"
"(nty_date,notification_type,user_count)"
"VALUES (%s,%s,%s)")
data = (time.strftime('%Y-%m-%d %H:%M:%S'),notification_type, usercount)
linker1 = cursor.execute(query,data)
print (linker1)
cursor.close()
connection.close()
INSERT
query.. please check the syntax afterVALUES
clause>>> cursor = connection.cursor() >>> timestamp = time.strftime("%Y-%m-%d %X") >>> notification_type = "Notify Inactive users" >>> usercount = 45 >>> query = "INSERT INTO iaas.bulk_notification_history (nty_date,notification_type,user_count) VALUES ('%s','%s',%d)" %(timestamp,notification_type,usercount) >>>linker1 = cursor.execute(query) >>> linker1 >>> print (linker1) None
cursor.execute(query, parameters)
.query = ("""INSERT INTO iaas.bulk_notification_history " "(nty_date,notification_type,user_count)" "VALUES (%s, %s, %d)""") data = (timestamp, notification_type, usercount) print (query) linker1 = cursor.execute(query,data) print (linker1)