lynxx
lynxx

Reputation: 612

Inserting into a database table not working with Python

I am inserting into a table using the following code:

## Connection established ##

sql = """ INSERT INTO Singer ( name ) VALUES( %s ) """

params = ('Rihanna',)

cursor.execute(sql, params)

cursor.fetchall()  ## Result - into no result set 
cursor.description ## Result - Nonetype

I am not able to understand where am I going wrong?

Thanks

Upvotes: 0

Views: 47

Answers (1)

ByteFlowr
ByteFlowr

Reputation: 500

You have to commit your change.

cursor = conn.cursor()
sql = """ INSERT INTO Singer ( name ) VALUES( %s ) """

params = ('Rihanna',)

cursor.execute(sql, params)
conn.commit() # Important, apply changes to database!
cursor.fetchall()  ## Result - into no result set 
cursor.description ## Result - Nonetype

Upvotes: 2

Related Questions