Python-Sql Connection
r="yes"
import mysql.connector as cathode
anode=cathode.connect(host="localhost",user="root",password="12345",database="Pharmadeal")
if anode.is_connected():
print("we are on the right way")
d=anode.cursor()
while r=="yes":
print("1-insert data")
print("2-update data")
print("3-delete data")
print("4-display data")
f=int(input("enter your choice"))
if f==1:
a=int(input("enter id"))
e=input("enter name")
s=input("enter medicine")
g=int(input("enter price"))
h=input("enter address")
m="insert into details(ID,CUSTOMER,MEDICINE,PRICE,ADDRESS)values({},'{}','{}',{},'{}')".format(a,e,s,g,h)
d.execute(m)
anode.commit()
elif f==2:
print("1-update customer name")
print("2-update medicine")
print("3-update address")
s=int(input("enter your choice"))
if s==1:
b=input("enter previous customer name")
a=input("enter new name")
m="update details set customer='{}' where customer='{}'".format(a,b)
d.execute(m)
anode.commit()
elif s==2:
b=input("enter previous medicine")
a=input("enter new medicine")
m="update details set medicine='{}'where medicine='{}'".format(a,b)
d.execute(m)
anode.commit()
elif s==3:
b=input("enter previous address")
a=input("enter new address")
m="update details set address='{}' where address='{}'".format(a,b)
d.execute(m)
anode.commit()
elif f==3:
a=int(input("enter id"))
m="delete from details where id={}".format(a)
d.execute(m)
anode.commit()
elif f==4:
t="select * from details;"
d.execute(t)
z=d.fetchall()
for i in z:
print(i)
r=input("do you want more")
else:
print("you are out of programme")
Comments
Post a Comment