Hi i am creating a queries through python functions.
When i am trying to insert certain values : a succesfull insert appears but my query doesn't show up when i search the database by hand .
The code is this:
@post('/store_artist')
def store_artist():
conn = pymysql.connect(host='localhost', port=3306, user='root', passwd='', db='songs')
c = conn.cursor();
c.execute("SET NAMES 'utf8'");
c.execute("SET CHARACTER SET 'utf8'");
artist_name = request.forms.get('artist_name')
artist_surname = request.forms.get('artist_surname')
artist_bday = request.forms.get('artist_bday')
artist_id = request.forms.get('artist_id')
c.execute(("INSERT INTO kalitexnis (ar_taut,onoma,epitheto, etos_gen) VALUES (%s, %s, %s, %s)"),(int(artist_id),artist_name,artist_surname,int(artist_bday)))
result = c.fetchall()
return "Artist info successfully stored"
Any idea ? Thank you
1 Answer 1
You have to call conn.commit() after every insert and update query for the changes to be saved into the db.
Alternatively, you could call conn.autocommit(True), then the changes will be immediately saved in the db.
answered May 11, 2016 at 16:00
DeepSpace
82.2k12 gold badges119 silver badges166 bronze badges
Sign up to request clarification or add additional context in comments.
default
conn.commit(). Reference: dev.mysql.com/doc/connector-python/en/… stackoverflow.com/questions/384228/…