Prisha - Ip
Prisha - Ip
PROJECT
01 Declaration 1
02 Acknowledgement 2
03 Introduction 3
04 Working Procedure 4
08 Output 13-17
09 Bibliography 18
DECLARATION
Ms Prisha Mathur
1
ACKNOWLEDGEMENT
2
INTRODUCTION
3
Searching is more time consuming
4
WORKING DESCRIPTION
Then the user has to enter a choice according to which the input has to
be given.
If the user enters an invalid choice, the execution of the program
stops.
5
inserted into the table “submit” and the message “book submitted by
<name> ” is displayed on the screen.
If the choice is 4, then the user has to enter the bookcode and the
book with the given bookcode will be deleted from the table and the
message “Book with bookcode <bookcode> successfully deleted” is
displayed on the screen.
If the choice is 5, then all the books along with their details present in
the “books” table are displayed.
6
FUNCTIONS AND MODULES
MODULES:
import mysql.connector
FUNCTIONS:
connect():
This function establishes connection between Python and MySQL
cursor():
It is a special control structure that facilitates the row-by- row
processing of records in the result set.
execute():
This function is used to execute the sql query and retrieve records
using python.
7
The syntax is:
<cursor object>.execute(<sql query string>)
def():
A function is a block of code which only runs when it is called.
fetchall():
This function will return all the rows from the result set in the form of
a tuple containing the records.
fetchone():
This function will return one row from the result set in the form of a
tuple containing the records.
commit():
It makes all the changes made by statements issued permanent.
8
DETAILED DESCRIPTION
9
2. The table issue contains the following columns:
i. name
ii. regno
iii. bookcode
iv. issue_date
10
3. The table submit contains the following columns:
i. name
ii. regno
iii. bookcode
iv. submission_date
11
SOURCE CODE
FOR MySQL:
use library;
FOR PYTHON:
if mycon.is_connected():
print("Successfully connected to mysql database")
def addbook():
bookname=input("Enter the name of the book:")
bookcode=int(input("Enter the code of the book:"))
subject=input("Enter the subject of the book:")
totalbooks=int(input("Enter the total number of books:"))
data=(bookname,bookcode,subject,totalbooks)
sqlinsert="insert into books values(%s,%s,%s,%s)"
mycursor=mycon.cursor()
mycursor.execute(sqlinsert,data)
mycon.commit()
print()
print("...........-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*...........")
print("data entered successfully")
main()
def issuebook():
iname=input("Enter the name of the student:")
regno=int(input("Enter the registration no:"))
bcode=int(input("Enter the code of the book:"))
issue=input("Enter the date of issuing the book:")
data=(iname,regno,bcode,issue)
i="insert into issue values(%s,%s,%s,%s)"
mycursor=mycon.cursor()
mycursor.execute(i,data)
mycon.commit()
13
print()
print("...........-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*...........")
print("book issued to:",iname)
print()
bookup(bcode,-1)
def submitbook():
iname=input("Enter the name of the student:")
regno=int(input("Enter the registration no:"))
bcode=int(input("Enter the code of the book:"))
subdate=input("Enter the date of submission of the book:")
data = (iname,regno,bcode,subdate)
i = "insert into submit values(%s,%s,%s,%s)"
mycursor = mycon.cursor()
mycursor.execute(i, data)
mycon.commit()
print("...........-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*...........")
print("book submitted by:", iname)
bookup(bcode,1)
def bookup(bcode,u):
i = "select totalbooks from books where bookcode=%s"
data=(bcode,)
mycursor = mycon.cursor()
mycursor.execute(i, data)
myresult=mycursor.fetchone()
t=myresult[0]+u
sqlinsert="update books set totalbooks=%s where
bookcode= %s "
d=(t,bcode)
mycursor.execute(sqlinsert,d)
mycon.commit()
main()
14
def deletebooks():
db=input("Enter the book code:")
i = "delete from books where bookcode=%s"
data=(db,)
mycursor = mycon.cursor()
mycursor.execute(i, data)
mycon.commit()
print("Book with bookcode",db,"succesfully deleted")
main()
def displaybooks():
i='select * from books'
mycursor = mycon.cursor()
mycursor.execute(i)
myresult=mycursor.fetchall()
for i in myresult:
print("book name:",i[0])
print("book code:", i[1])
print("subject of book:", i[2])
print("total books:", i[3])
print()
print("...........-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*...........")
main()
def main():
print("**********LIBRARY MANAGEMENT
SYSTEM**********")
print("""1.ADD books
2.ISSUE books
3.SUBMIT books
4.DELETE books
5.DISPLAY books""")
15
choice=input("Enter the task number:")
print("...........-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*...........")
if choice=='1':
addbook()
elif choice=='2':
issuebook()
elif choice=='3':
submitbook()
elif choice=='4':
deletebooks()
elif choice=='5':
displaybooks()
else:
print("#### WRONG CHOICE #### ")
main()
def passwd():
ps=input("Enter password:")
if ps=="LMS":
main()
else:
print("Wrong password")
passwd()
passwd()
16
OUTPUT
1. Add a book
MySQL Output:
17
2. Issue a book
MySQL Output:
18
3. Submit a book
MySQL Output:
19
4. Delete a book
MySQL Output:
20
5. Display books
21
BIBLIOGRAPHY
22
https://www.slideshare.net/DarshitVaghasiya1/library-
management-python-mysql
https://www.studocu.com/in/document/kendriya-vidyalaya-
hebbal/computer-science/pdf-for-cd-class-12-ak-this-code-for-
library-management-project-this-in-python-and-mysql/43783381
23