Advertisements
Advertisements
Question
MySQL database named WarehouseDB has a product_inventory table in MySQL which contains the following attributes:
- Item_code: Item code (Integer)
- Product_name: Name of product (String)
- Quantity: Quantity of product (Integer)
- Cost: Cost of product (Integer)
Consider the following details to establish Python-MySQL connectivity:
- Username: admin_user
- Password: warehouse2024
- Host: localhost
Write a Python program to change the quantity of the product to 91 whose Item_code is 208 in the product_inventory table.
Code Writing
Advertisements
Solution
import mysql.connector
connection =
mysql.connector.connect(host='localhost',user='admin_user',password='warehouse
2024',database='WarehouseDB')
cursor = connection.cursor()
update_query = "UPDATE product_inventory SET Quantity = 91 WHERE
Item_code = 208"
cursor.execute(update_query)
connection.commit()
print("Data updated successfully.")
cursor.close()
connection.close()shaalaa.com
Is there an error in this question or solution?
