0

I have some problem inserting data in MySQL. The program is running without any errors but the values are not getting inserted. Below is the code. I doubt there is some mistake in format specifiers.The python version I am using is 3.5.3. Thanks in advance.

#!/usr/bin/python 

import MySQLdb 

# Open database connection 
db = MySQLdb.connect("localhost","root","pwd","project") 

# prepare a cursor object using cursor() method 
cursor = db.cursor() 

add_metric = ("INSERT INTO metrics "  "(clicks, pageviews, sessions, source, browser,device_type)"
               "VALUES (%s, %s, %s, %s, %s,%s)")

data_metric = (5,6,7,'s','a','f')

cursor.execute(add_metric, data_metric)

cursor.close();

db.close();

1 Answer 1

2

I would say that you have to commit your connection or set autoCommit to true

db.autocommit(True);

or

db.commit(); before closing the cursor

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.