0% found this document useful (0 votes)
12 views

AryanP Py

This document outlines a Python program for managing a library database using MySQL. It includes functions to add, issue, submit, delete and display books in database tables. The program connects to a MySQL database called Library on localhost, defines tables for books, issues and submissions, then provides a menu driven interface to call functions for each database action.

Uploaded by

Rushabh Bhavar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

AryanP Py

This document outlines a Python program for managing a library database using MySQL. It includes functions to add, issue, submit, delete and display books in database tables. The program connects to a MySQL database called Library on localhost, defines tables for books, issues and submissions, then provides a menu driven interface to call functions for each database action.

Uploaded by

Rushabh Bhavar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

LIBRARY MANAGEMENT

DBMS: MySql
Host: Localhost
User: root
Passward: Manoj@123
Database: Library
Table Structures: As per the Screenshot given below:

Table Names:
Books Table:

Book Issue Table And Submit :


Python Code :-
import mysql.connector as a
con=a.connect(host="localhost",user="root",password="12340",databas
e="Library")

def addB():
bn=input("Enter Book Name:")
c=input("Enter Book Code:")
t=input("Total Books:")
s=input("Enter Subject:")
data=(bn,c,t,s)
sql='insert into books values(%s,%s,%s,%s)'
c=con.cursor()
c.execute(sql,data)
con.commit()

print(">_______________________________________________
____<")
print("Data Entered Successfully")
main()

def issueB():
n=input("Enter Name :")
r=input("Enter Reg No:")
co=input("Enter Book Coode:")
d=input ("Enter Date:")
a="insert into issue values(%s,%s,%s,%s)"
data=(n,r,co,d)
c=con.cursor()
c.execute(a,data)
con.commit()
print(">_______________________________________________
_____<")
print("Book issued to :",n)
bookup(co,-1)

def submitB():
n=input("Enter Name:")
r=input("Enter Reg No :")
co=input("Enter Book Code:")
d=input("Enter Date:")
a="insert into submit values(%s,%s,%s,%s)'"
data=(n,r,co,d)
c=con.cursor()
c.execute(a,data)
con.commit()

print(">_______________________________________________
_____<")
print("Book Submitted from:",n)
bookup(co,1)

def bookup(co,u):
a="select TOTAL from book where BCODE=%s"
data=(co,)
c=con.cursor()
c.execute(a,d)
myresult=c.fetchone()
t=myresult[0]+u
sql="updata book set TOTAL=%s where BCODE=%s"
d=(t,co)
c.execute(sql,d)
con.commit()
main()

def deleteB():
ac=input("Enter Book Code:")
a="delete from book where BCODE=%s"
data=(ac,)
c=con.cursor()
c.execute(a,data)
con.commit()
main()

def displayB():
a="select* from books"
c=con.cursor()
c.execute(a)
myresult=c.fetchall()
for i in myresult:
print("Book Name :",i[0])
print("Book Code :",i[1])
print("Total :",i[2])
print("Subject:",i[3])

print(">_______________________________________________
_<")
main()

def main():
print("""
LIBRARY MANAGER

1.ADD BOOK
2.ISSUE BOOK
3.SUBMIT BOOK
4.DELETE BOOK
5.DISPLAY BOOK

""")
choice=input("Enter Task No:")

print(">_______________________________________________
____<")
if(choice=='1'):
addB()
elif(choice=='2'):
issueB()
elif(choice=='3'):
submitB()
elif(choice=='4'):
deleteB()
elif(choice=='5'):
displayB()
else:
print("Wrong Choice.........")
main()
def pswd():
ps=input("Enter Password:")
if ps=="PAL123":
main()
else:
print("Wrong Password")
pswd()
pswd()
OUUTPUT :
INSERT DETAILS
BY : ARYAN B
CLASS :12

You might also like