Chathuri Fernando
Chathuri Fernando

Reputation: 972

MYSQL data insert query doesn't work in Python

This is my insert query.

rule_result = max(item_counts.iteritems(), key=operator.itemgetter(1))[0]

# DB connection
conn = MySQLdb.connect(host="localhost",user="root",passwd="",db="chat_app",use_unicode=True,charset="utf8")
x = conn.cursor()

cursor.execute('''INSERT into rule_based_results (emotion) values (%s)''',(rule_result))
conn.commit()
conn.close()

There isn't any error. But this query doesn't work. Can anyone tell me what is the problem with my query.

Upvotes: 2

Views: 459

Answers (1)

ILostMySpoon
ILostMySpoon

Reputation: 2409

You initialized x to your connection's cursor object but never used it.

x.execute('''INSERT into rule_based_results (emotion) values (%s)''',(rule_result))
conn.commit()
x.close()
conn.close()

Upvotes: 1

Related Questions