1

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

4
  • Are each of your values filled and not empty? Commented May 11, 2016 at 15:55
  • 1
    I'm guessing, so not an answer: You need conn.commit(). Reference: dev.mysql.com/doc/connector-python/en/… stackoverflow.com/questions/384228/… Commented May 11, 2016 at 15:59
  • yep . Just printed them in python to be sure Commented May 11, 2016 at 16:00
  • @Robᵩ youuuuu are right :) Thank you man Commented May 11, 2016 at 16:03

1 Answer 1

2

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.

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

3 Comments

Is it c.commit() or conn.commit(), or does it matter?
@Robᵩ conn.commit() is what I have always used based on the tutorials I read a while back
@Robᵩ Thanks, it is indeed conn.commit(). I will update my answer

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.