0% found this document useful (0 votes)
1 views13 pages

Python-Mysql Interface Questions&Answers

The document contains multiple Python scripts that connect to different MySQL databases to perform various operations. These operations include updating product quantities, changing the status of expired medicines, deleting a theatre record, and deleting a specific placement record. Each script establishes a connection, executes an SQL query, commits the changes, and then closes the connection.

Uploaded by

Asha Maid
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views13 pages

Python-Mysql Interface Questions&Answers

The document contains multiple Python scripts that connect to different MySQL databases to perform various operations. These operations include updating product quantities, changing the status of expired medicines, deleting a theatre record, and deleting a specific placement record. Each script establishes a connection, executes an SQL query, commits the changes, and then closes the connection.

Uploaded by

Asha Maid
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

import mysql.

connector

# Establish connection

conn = [Link](

host="localhost",

user="admin_user",

password="warehouse2024",

database="WarehouseDB")

# Create cursor object

cursor = [Link]()

# SQL query to update Quantity

query = "UPDATE product_inventory SET Quantity = 91 WHERE Item_code = 208"

# Execute query

[Link](query)

# Save changes

[Link]()

print("Quantity updated successfully.")

# Close connection

[Link]()
import [Link]

def ChangeStatus():

# Establish connection

conn = [Link](

host="localhost",

user="root",

password="tiger",

database="PHARMACY" )

# Create cursor object

cursor = [Link]()

# Update Status to DISCARD for expired medicines

query = "UPDATE MEDICINES SET Status = 'DISCARD' WHERE Expiry < '2022-12-31' “

[Link](query)

[Link]()

print("Status updated successfully.")

[Link]()

# Function Call

ChangeStatus()
def Delete_Theatre():

import [Link]

conn = [Link](host="localhost",

user="root",

password="Ex2025",

database="CINEMA")

cur = [Link]()

thid = input("Enter Theatre ID : ")

# Delete query
query = "DELETE FROM THEATRE WHERE Th_ID='{}' ".format(thid)

# Execute query
[Link](query)

[Link]()

[Link]()

import [Link]

# Establish connection with MySQL


conn = [Link](
host="localhost",
user="root",
password="job",
database="Agency")
# Create cursor object
cursor = [Link]()
# SQL query to delete record of Raman
query = "DELETE FROM Placement WHERE CName='Raman'"
# Execute query
[Link](query)
# Save changes
[Link]()
print([Link], "record deleted successfully.")
# Close connection
[Link]()
#2
#3

#4

You might also like