Library Management
Library Management
connector
db1 = None
def connect():
global db1
db1 = mysql.connector.connect(host="localhost",user="root",
password="root",
database = "project"
def showMembers():
c1 = db1.cursor()
res = c1.fetchall()
print("-"*40)
print("-"*40)
print("-"*40)
def login():
print("-" * 40)
print("-" * 40)
print("\t LOGIN")
val = (un,pw)
c2 = db1.cursor()
c2.execute(q,val)
res = c2.fetchall()
print("-" * 50)
if len(res) == 0:
print("-" * 50)
return False
else:
print("-" * 50)
return True
def delMember():
print("-" * 40)
print("\tDELETING A MEMBER")
print("-" * 40)
cursor1 = db1.cursor()
cursor1.execute(q)
db1.commit()
def addMember():
print("-" * 50)
print("-" * 50)
cursor1 = db1.cursor()
val = (mid,name,phone,email)
cursor1.execute(q,val)
db1.commit()
def showMembers():
cursor1 = db1.cursor()
res = cursor1.fetchall()
print("-" * 50)
print("-" * 50)
for k in res:
def delBook():
print("-" * 40)
print("\tDELETING A BOOK")
print("-" * 40)
cursor1 = db1.cursor()
cursor1.execute(q)
db1.commit()
print("-" * 50)
print("-" * 50)
cursor1 = db1.cursor()
val = (bid,title,author,pub,cost)
cursor1.execute(q,val)
db1.commit()
def showBooks():
cursor1 = db1.cursor()
res = cursor1.fetchall()
print("-" * 50)
print("-" * 50)
for k in res:
cursor1 = db1.cursor()
res = cursor1.fetchall()
print("-" * 40)
for k in res:
print(k[0],"\t",k[1],"\t",k[2])
print("-" * 40)
def showReturned():
cursor1 = db1.cursor()
res = cursor1.fetchall()
print("-" * 50)
for k in res:
print(k[0],"\t",k[1],"\t",k[2],"\t",k[3])
print("-" * 50)
def issueBook():
cursor1 = db1.cursor()
cursor1.execute(q)
res = cursor1.fetchall()
if len(res)== 0:
data = (mid,bid,doi)
cursor1.execute(q,data)
db1.commit()
print("-" * 40)
print("-" * 40)
else:
print("-" * 40)
print("-" * 40)
def returnBook():
q ="select dateofissue from issue where bookid='" + bid +"' and mid='" + mid +"'"
cursor1 = db1.cursor()
cursor1.execute(q)
res = cursor1.fetchall()
if len(res)== 0:
print("-" * 40)
print("-" * 40)
else:
q = "delete from issue where bookid='" + bid + "' and mid='" + mid + "'"
cursor1.execute(q)
db1.commit()
data = (mid,bid,res[0][0],dort)
cursor1.execute(q,data)
db1.commit()
connect()
print("Connected")
if login():
while True:
print("-" * 50)
print("-" * 50)
print("Press 11 - Quit")
if ch == 1:
addMember()
elif ch == 2:
delMember()
elif ch == 3:
showMembers()
elif ch == 4:
addBook()
elif ch == 5:
delBook()
elif ch == 6:
showBooks()
elif ch == 7:
issueBook()
elif ch == 8:
returnBook()
elif ch == 9:
showIssued()
elif ch == 10:
showReturned()
elif ch == 11:
break