2

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.

2
  • What exactly doesn't work? Commented Jun 15, 2017 at 16:18
  • Data not insert to the Database. Commented Jun 15, 2017 at 16:18

1 Answer 1

1

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()
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you I made my mistake.

Your Answer

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.