Advertisements
Advertisements
Question
Sunil wants to write a program in Python to update the quantity to 20 of the records whose item code is 111 in the table named shop in MySQL database named Keeper.
The table shop in MySQL contains the following attributes:
Item_code:Item code (Integer)Item_name:Name of item (String)Qty:Quantity of item (Integer)Price:Price of item (Integer)
Consider the following to establish connectivity between Python and MySQL:
- Username:
admin - Password:
Shopping - Host:
localhost
Code Writing
Advertisements
Solution
import mysql.connector as m
try:
con=m.connect(host='localhost',user=' Adm
in', passwd='Shopping',
database='keeper')
mycursor=con.cursor()
mycursor.execute("Update shop set Qty=20
where Item_Code=111")
con.commit()
except:
con.close()shaalaa.com
Is there an error in this question or solution?
