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

panos
  • 23
  • 5
  • Are each of your values filled and not empty? – Matt May 11 '16 at 15:55
  • 1
    I'm guessing, so not an answer: You need `conn.commit()`. Reference: https://dev.mysql.com/doc/connector-python/en/connector-python-api-mysqlconnection-commit.html http://stackoverflow.com/questions/384228/database-does-not-update-automatically-with-mysql-and-python – Robᵩ May 11 '16 at 15:59
  • yep . Just printed them in python to be sure – panos May 11 '16 at 16:00
  • @Robᵩ youuuuu are right :) Thank you man – panos May 11 '16 at 16:03

1 Answers1

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.

DeepSpace
  • 78,697
  • 11
  • 109
  • 154