import mysql.connector
import datetime
mydb=mysql.connector.connect(host="localhost",\
user="root",\
passwd="root",\
database="practicalexam")
mycursor=mydb.cursor()
def teacheradd():
L=[]
tno=int(input("Enter tno:"))
L.append(tno)
tname=input("Enter tname:")
L.append(tname)
tsalary=int(input("Enter tsalary:"))
L.append(tsalary)
value=L
value=(tno,tname,tsalary)
sql="insert into teacher(tno,tname,tsalary)values(%s,%s,%s)"
mycursor.execute(sql,value)
mydb.commit()
def teachersearch():
tn=int(input("Enter tno to search"))
rl=(tn,)
sql="select * from teacher where tno=%s"
mycursor.execute(sql,rl)
res=mycursor.fetchall()
print("Details are as follows:")
print("(tno,tname,tsalary)")
for x in res:
print(x)
def teacherdelete():
t=int(input("Enter the tno to delete:"))
rl=(t,)
sql="delete from teacher where tno=%s"
mycursor.execute(sql,rl)
mydb.commit()
def teacherupdate():
t=int(input("Enter the tno to update:"))
sql=("select * from teacher where tno=%s")
rl=(t,)
value=int(input("Enter the amount:"))
#rll=(value,)
sql=("update teacher set tsalary=tsalary+%s where tno=%s")
data=(value,t)
mycursor.execute(sql,data)
mydb.commit()
#now=datetime.datetime.now()
#trID="S"+str(now.year)+str(now.month)+str(now.day)+str(now.hour)+str(now.minute)+str(now.second)
#print("Reference ID is",trID)
def menu():
print("*************************")
print("Press 1- To add data")
print("Press 2- To search record")
print("Press 3- To delete record")
print("Press 4- To Update esalary record")
print("*************************")
userinput=int(input("Please select an option from above"))
if(userinput==1):
teacheradd()
elif(userinput==2):
teachersearch()
elif(userinput==3):
teacherdelete()
elif(userinput==4):
teacherupdate()
else:
print("Wrong Choice")
def runagain():
again=input("\Want to run again y/n?")
while(again=='y'):
menu()
again=input("\nWant to run again y/n?")
menu()
runagain()
print("Thanks for using Program")
import datetime
mydb=mysql.connector.connect(host="localhost",\
user="root",\
passwd="root",\
database="practicalexam")
mycursor=mydb.cursor()
def teacheradd():
L=[]
tno=int(input("Enter tno:"))
L.append(tno)
tname=input("Enter tname:")
L.append(tname)
tsalary=int(input("Enter tsalary:"))
L.append(tsalary)
value=L
value=(tno,tname,tsalary)
sql="insert into teacher(tno,tname,tsalary)values(%s,%s,%s)"
mycursor.execute(sql,value)
mydb.commit()
def teachersearch():
tn=int(input("Enter tno to search"))
rl=(tn,)
sql="select * from teacher where tno=%s"
mycursor.execute(sql,rl)
res=mycursor.fetchall()
print("Details are as follows:")
print("(tno,tname,tsalary)")
for x in res:
print(x)
def teacherdelete():
t=int(input("Enter the tno to delete:"))
rl=(t,)
sql="delete from teacher where tno=%s"
mycursor.execute(sql,rl)
mydb.commit()
def teacherupdate():
t=int(input("Enter the tno to update:"))
sql=("select * from teacher where tno=%s")
rl=(t,)
value=int(input("Enter the amount:"))
#rll=(value,)
sql=("update teacher set tsalary=tsalary+%s where tno=%s")
data=(value,t)
mycursor.execute(sql,data)
mydb.commit()
#now=datetime.datetime.now()
#trID="S"+str(now.year)+str(now.month)+str(now.day)+str(now.hour)+str(now.minute)+str(now.second)
#print("Reference ID is",trID)
def menu():
print("*************************")
print("Press 1- To add data")
print("Press 2- To search record")
print("Press 3- To delete record")
print("Press 4- To Update esalary record")
print("*************************")
userinput=int(input("Please select an option from above"))
if(userinput==1):
teacheradd()
elif(userinput==2):
teachersearch()
elif(userinput==3):
teacherdelete()
elif(userinput==4):
teacherupdate()
else:
print("Wrong Choice")
def runagain():
again=input("\Want to run again y/n?")
while(again=='y'):
menu()
again=input("\nWant to run again y/n?")
menu()
runagain()
print("Thanks for using Program")
Comments
Post a Comment