0% found this document useful (0 votes)
2 views28 pages

Import Mysql

The document is a Python script for a Library Management System that uses MySQL for database operations. It includes functions to insert, update, delete, search, and display records for books, branches, customers, issued books, returned books, and staff. The script interacts with the user through console inputs to manage library data effectively.

Uploaded by

rajputalpumanish
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views28 pages

Import Mysql

The document is a Python script for a Library Management System that uses MySQL for database operations. It includes functions to insert, update, delete, search, and display records for books, branches, customers, issued books, returned books, and staff. The script interacts with the user through console inputs to manage library data effectively.

Uploaded by

rajputalpumanish
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 28

import mysql.

connector as lib

con_obj=lib.connect(host='localhost',user='root',passwd='3110vish',database='library',charset='utf8')

cur_obj=con_obj.cursor()

def insert_book():

print("************WELCOME TO LIBRARY MANAGEMENT SYSTEM **************")

print("*******PLEASE FILL THE DETAILS YOU WANT TO INSERT**************")

ID=int(input('Enter book ID :'))

Name=input('Enter book name :')

Author=input('Enter book author name :')

Type=input('Enter book type :')

Price=int(input('Enter book price :'))

Rentprice=int(input('Enter book rented price :'))

Wing=input("Enter wing:")

Shelve=int(input("Enter shelve no:"))

data="insert into
books(Book_ID,Book_name,Book_Author,Book_Type,Book_Price,Book_Rentprice,Wing,Shelves)
values({},'{}','{}','{}',{},{},'{}','{}')".format(ID,Name,Author,Type,Price,Rentprice,Wing,Shelve)

cur_obj.execute(data)

con_obj.commit()

print('*'*400)

print('*'*400)

print('*'*400)

print('Book Inserted successfully!')


option()

def update_book():

print("*********WELCOME TO LIBRARY MANAGEMENT SYSTEM******")

print("*********PLEASE FILL THE DETAILS YOU WANT TO UPDATE**********")

ID=int(input("Enter Book ID:"))

Name=input("Enter Book Name:")

Author=input("Enter Book Author name:")

Type=input("Enter Book Type:")

Price=int(input("Enter Book Price:"))

Rentprice=int(input("Enter Book Rent Price:"))

cur_obj=con_obj.cursor()

data="update books set


Book_Name='{}',Book_Author='{}',Book_Type='{}',Book_Price={},Book_Rentprice={} where
Book_ID={}".format(Name,Author,Type,Price,Rentprice,ID)

cur_obj.execute(data)

con_obj.commit()

print('*'*500)

print('*'*500)

print('*'*500)

print(" Book is updated Successfully!")

option()

def delete_book():
print("******************WELCOME TO LIBRARY MANAGEMENT SYSTEM*****************")

print("**************PLEASE ENTER THE RECORD YOU WANT TO DELETE*****************")

ID=int(input("Enter Book ID:"))

data="delete from books where Book_ID={}".format(ID)

cur_obj.execute(data)

con_obj.commit()

print('*'*500)

print('*'*500)

print('*'*500)

print("Book details has been Deleted")

option()

def search_book():

print("************WELCOME TO LIBRARY MANAGEMENT SYSTEM****************")

print("**********PLEASE ENTER THE DETAILS YOU WANT TO SEARCH**********")

ID=int(input("Enter Book ID:"))

cur_obj=con_obj.cursor()

data="select * from books where Book_ID={}".format(ID)

cur_obj.execute(data)

row=cur_obj.fetchall()

print(row)

con_obj.close()
print('*'*500)

print('*'*500)

print('*'*500)

print("All the Book Details has been Searched!")

option()

def display_book():

print("***************WELCOME TO LIBRARY MANAGEMENT SYSTEM***************")

print("*****************ALL THE DETAILS OF YOUR TABLE STATED DISPLAYING************")

data="select * from books"

cur_obj.execute(data)

row=cur_obj.fetchall()

print(row)

con_obj.close()

print('*'*500)

print('*'*500)

print('*'*500)

print("All the details has been Displayed!")

option()

def insert_branch():
print("***********WELCOME TO LIBRARY MANAGEMENT SYSTEM*************")

print("***********PLEASE FILL THE INFORMATION YOU HAVE TO INSERTED**********")

ID=int(input("Enter Branch id:"))

Name=input("Enter Branch name:")

Location=input("Enter Branch Location:")

data="insert into branch(Branch_ID,Branch_Name,Branch_location)


values({},'{}','{}')".format(ID,Name,Location)

cur_obj.execute(data)

con_obj.commit()

print('*'*500)

print('*'*500)

print('*'*500)

print('Branch Insertion is successfull!')

option()

def update_branch():

print("***************WELCOME TO LIBRARY MANAGEMENT SYSTEM******************")

print("***************PLEASE FILL THE DETAILS YOU WANT UPDATE******************")

ID=int(input("Enter Branch ID:"))

Name=input("Enter Branch Name:")

Location=input("Enter Branch Location:")

cur_obj=con_obj.cursor()

data="update branch set Branch_Name='{}',Branch_Location='{}' where


Branch_ID={}".format(Name,Location,ID)
cur_obj.execute(data)

con_obj.commit()

print('*'*500)

print('*'*500)

print('*'*500)

print("Updation of all the details has been Sucessfull Done!")

option()

def delete_branch():

print("**************WELCOME TO LIBRARY MANAGEMENT SYSTEM***********")

print("**************PLEASE ENTER THE DETAILS YOU WANT TO DELETE**************")

ID=int(input("Enter Branch ID:"))

cur_obj=con_obj.cursor()

cur_obj.execute("delete from branch where Branch_ID={}".format(ID))

con_obj.commit()

print('*'*500)

print('*'*500)

print('*'*500)

print("Details has been Delete Sucessfully!")

option()
def search_branch():

print("**************WELCOME TO LIBRARY MANAGEMENT SYSEM******************")

print("***************PLEASE ENTER THE DETAILS YOUR WANT TO SEARCH***********")

ID=int(input("Enter Branch ID:"))

cus_obj=con_obj.cursor()

data="select * from branch where Branch_ID={}".format(ID)

cur_obj.execute(data)

row=cur_obj.fetchall()

print(row)

con_obj.close()

print('*'*500)

print('*'*500)

print('*'*500)

print("Branch search is sucessfull!")

option()

def display_branch():

print("***************WELCOME TO LIBRARY MANAGEMENT SYSTEM************")

print("**************ALL THE DEATILS HAS BEEN STARTED DISPLAYING*********")

data="select * from branch"

cur_obj.execute(data)
row=cur_obj.fetchall()

print(row)

con_obj.close()

print('*'*500)

print('*'*500)

print('*'*500)

print("Branch Details has been Sucessfully Displayed")

option()

def insert_customer():

print("***********WELCOME TO LIBRARY MANAGEMENT SYSTEM****************")

print("**********PLEASE FILL THE DETAILS YOU WANT TO INSERT*************")

ID=int(input("Enter Customer ID:"))

Name=input("Enter Customer Name:")

Email=input("Enter Customer Email address:")

Address=input("Enter Customer Address:")

Phno=int(input("Enter Customer Phone No:"))

BranchID=int(input("Enter Branch Id:"))

data="insert into
customer(Customer_ID,Coustomer_Name,Coustomer_Email,Coustermer_Address,Coustermer_Phon_n
o,Branch_ID) values({},'{}','{}','{}',{},{})".format(ID,Name,Email,Address,Phno,BranchID)

cur_obj.execute(data)
con_obj.commit()

print('*'*500)

print('*'*500)

print('*'*500)

print("Customer Details has been Inserted")

option()

def update_customer():

print("***************WELCOME TO LIBRARY MANGEMENT SYSTEM****************")

print("***************PLEASE ENTER THE DETAILS YOU WANT TO UPDATE***********")

ID=int(input("Enter Customer ID:"))

Name=input("Enter Customer Name:")

Email=input("Enter Customer Email address:")

Address=input("Enter Customer Address:")

Phno=int(input("Enter Customer Phone No:"))

BranchID=int(input("Enter Branch ID:"))

cur_obj=con_obj.cursor()

data="update customer set


Coustomer_Name='{}',Coustomer_Email='{}',Coustomer_Address='{}',Coustomer_Phon_no={},Branch_ID
={} where Customer_ID={}".format(Nmae,Email,Address,Phno,BranchID,ID)

cur_obj.execute(data)

con_obj.commit()

print('*'*500)
print('*'*500)

print('*'*500)

print("All the Details has been Updated")

option()

def delete_customer():

print("********************WELCOME TO LIBRARY MANAGEMENT SYSTEM**************")

print("********************PLEASE ENTER DETAILS YOU WANT TO DELETE**************")

ID=int(input("Enter Customer ID:"))

cur_obj=con_obj.cursor()

data="delete from customer where Customer_ID={}".format(ID)

cur_obj.execute(data)

con_obj.commit()

print('*'*500)

print('*'*500)

print('*'*500)

print("All the details has been Deleted!")

option()

def search_customer():

print("**************WELCOME TO LIBRARY MANAGEMENT SYSTEM***************")

print("**************PLEASE ENTER THE DETAILS YOU WANT TO SEARCH****************")


ID=int(input("Enter customer ID:"))

cur_obj=con_obj.cursor()

data="select * from customer where Customer_ID={}".format(ID)

cur_obj.execute(data)

row=cur_obj.fetchall()

print(row)

con_obj.close()

print('*'*500)

print('*'*500)

print('*'*500)

print("All the details has been Searched Sucessfully!")

option()

def display_customer():

print("***********WELCOME TO LIBRARY MANAGEMENT SYSTEM*******************")

print("***********DISPLAY OF ALL THE DETAILS HAS BEEN STATED*************")

data="select * from customer"

record=cur_obj.execute(data)

print(record)

con_obj.close()
print('*'*500)

print('*'*500)

print('*'*500)

print("All the details has been Displayed!")

option()

def insert_issuebook():

print("*************WELCOME TO LIBRARY MANAGEMEN SYSTEM*************")

print("*************PLEASE FILL THE DETAILS YOU WANT TO INSERT***********")

ID=int(input('Enter Book ID :'))

Name=input('Enter Book Name :')

Issuedate=input('Enter Issue date :')

Expirydate=input('Enter Expiry date:')

CustomerID=int(input('Enter Customer ID:'))

cur_obj=con_obj.cursor()

data="insert into issue(Book_ID,Book_Name,Issue_Date,Expiry_Date,Customer_ID)


values({},'{}','{}','{}',{})".format(ID,Name,Issuedate,Expirydate,CustomerID)

cur_obj.execute(data)

con_obj.commit()

print('*'*500)

print('*'*500)

print('*'*500)

print("Details of BooK Issued has been Inserted")

option()

def update_issuebook():
print("**************** WELCOME TO LIBRARY MANAGEMENT SYSTEM*******************")

print("****************PLEASE FILL THE DETAILS YOU WANT TO UPDATE******************")

ID=int(input("ENTER BOOK ID :"))

Name=input("ENTER BOOK NAME")

Issuedate=int(input("ENTER ISSUE DATE :"))

Expirydate=int(input("ENTER EXPIRY DATE"))

cur_obj=con_obj.cursor()

data="update issue set Book_Name='{}',Issue_Date='{},Expiry_Date'{}' where


Customer_ID={}".format(Name,Issuedate,Expirydate,ID)

cur_obj.execute(data)

con_obj.commit()

print('*'*500)

print('*'*500)

print('*'*500)

print("DETAILS OF BOOK HAS BEEN SUCESSFULLY UPDATED")

option()

def delete_issuebook():

print("******************WELCOME TO LIBRARY MANAGEMENT


SYSTEM*********************")

print("******************PLEASE FILL THE DETAILS YOU WANT TO


DELETE*******************")

ID=int(input("ENTER BOOK ID"))


cur_obj=con_obj.cursor()

data="delete from issue where Book_ID={}".format(ID)

cur_obj.execute(data)

con_obj.commit()

print('*'*500)

print('*'*500)

print('*'*500)

print("DETAILS OF BOOK HAS BEEN SUCESSFULLY DELETED")

option()

def search_issuebook():

print("*********************WELCOME TO LIBRARY MANAGEMENT


SYSTEM****************************")

print("*********************PLEASE FILL THE DETAILS YOU WANT TO


SEARCH**************************")

ID=int(input("ENTER BOOK ID"))

cur_obj=con_obj.cursor()

data="select * from issue where Book_ID={}".format(ID)

cur_obj.execute(data)

row=cur_obj.fetchall()

print(row)

con_obj.close()
print('*'*500)

print('*'*500)

print('*'*500)

print("DETAILS OF BOOK HAS BEEN SUCESSFULLY SEARCHED")

option()

def display_issuebook():

print("**************WELCOME TO LIBRARY MANGEMENT SYSTEM*************")

print("**************DETAILS OF ALL THE BOOKS HAS BEEN DISPLAYED*************")

data="select * from issue"

cur_obj.exeute(data)

row=cur_obj.fetchall()

print(row)

con_obj.close()

print('*'*500)

print('*'*500)

print('*'*500)

print("DETAILS OF ALL THE BOOKS HAS BEEN DISPLAYED")

option()

def insert_returnbook():
print("*************WELCOME TO LIBRARY MANAGEMENT SYSTEM**********")

print("*********PLEASE FILL THE DETAILS YOU WANT TO INSERT**************")

ID=int(input("Enter book ID:"))

Name=input("Enter Book Name:")

Issuedate=input("Enter Issued Date:")

Expirydate=input("Enter Expiry Date:")

CustomerID=int(input("Enter Customer ID:"))

StaffID=int(input("Enter Staff ID:"))

data="insert into returnbooks(Book_ID,Book_Name,Issue_Date,Expiry_Date,Coustomer_ID,Staff_ID)


values({},'{}','{}','{}',{},{})".format(ID,Name,Issuedate,Expirydate,CustomerID,StaffID)

cur_obj.execute(data)

con_obj.commit()

print('*'*500)

print('*'*500)

print('*'*500)

print("Details of return book has been Inserted")

option()

def update_returnbook():

print("***************************WELCOME TO LIBRARY MANAGEMENT


SYSTEM**************")

print("***************************PLEASE FILL THE DETAILS YOU WANT TO


UPDATE*************")

ID=int(input("ENTER BOOK ID:"))

Name=input("ENTER BOOK NAME:")


Issuedate=input("ENTER ISSUED DATE:")

Expirydate=input("ENTER EXPIRY DATE:")

CustomerID=int(input("ENTER CUSTOMER ID:"))

StaffID=int(input("ENTER STAFF ID:"))

cur_obj=con_obj.cursor()

data="update returnbook set


Book_Name='{}',Issue_Date='{}',Expiry_Date='{}',Customer_ID={},Staff_ID={} where
Book_ID={}".format(Name,Issuedate,Expirydate,CustomerID,StaffID)

cur_obj.execute(data)

con_obj.commit()

print('*'*500)

print('*'*500)

print('*'*500)

print("DETAILS OF THE BOOK HAS BEEN UPDATED")

option()

def delete_returnbook():

print("******************************WELCOME TO LIBRARY MANAGEMENT


SYSTEM**********************")

print("******************************PLEASE FILL THE DETAILS YOU WANT TO


DELETE*********************")

ID=int(input("ENTER BOOK ID"))

cur_obj=con_obj.cursor()

data="delete from returnbook where Book_ID={}".format(ID)


cur_obj.execute(data)

con_obj.commi1t()

print('*'*500)

print('*'*500)

print('*'*500)

print("DETAILS OF THE BOOK HAS BEEN DELETED")

option()

def search_returnbook():

print("*****************************WELCOME TO LIBRARY MANAGEMENT


SYSTEM************************")

print("*****************************PLEASE FILL THE DETAILS YOU WANT TO


SEARCH***********************")

ID=int(input("ENTER BOOK ID "))

cur_obj=con_obj.cursor()

data="select * from returnbook where Book_ID={}".format(ID)

cur_obj.execute(data)

row=cur_obj.fetchall()

print(row)

con_obj.close()

print('*'*500)
print('*'*500)

print('*'*500)

print("DETAILS OF THE BOOK HAS BEEN SUCESSFULLY SEARCHED ")

option()

def display_returnbook():

print("********************************WELCOME TO LIBRARY MANAGEMENT


SYSTEM***************************")

print("********************************PLEASE FILL THE DETAILS YOU WANT TO


DISPLAY*************************")

data="select * from returnbook"

cur_obj.execute(data)

row=cur_obj.fetchall()

print(row)

con_obj.close()

print('*'*500)

print('*'*500)

print('*'*500)

print("DETAILS OF THE BOOK HAS BEEN DISPLAYED SUCESSFULLY")

option()

def insert_staff():

print("**********WELCOME TO LIBRARY MANAGEMENT SYSTEM*************")


print("***********PLEASE FILL THE DEATILS YOU WANT TO INSERT************")

ID=int(input("Enter Staff ID:"))

Name=input("Enter Staff Name:")

Address=input("Enter Staff Address:")

Gender=input("Enter Staff Gender:")

Phon_no=int(input("Enter Staff Phone No:"))

Branch_ID=int(input("Enter Branch ID:"))

data="insert into staff(Staff_ID,Staff_Name,Staff_address,Staff_Gender,Staff_Phon_no,Branch_ID)


values({},'{}','{}','{}',{},{})".format(ID,Name,Address,Gender,Phon_no,Branch_ID)

cur_obj.execute(data)

con_obj.commit()

print('*'*500)

print('*'*500)

print('*'*500)

print("Staff Details has been Insert")

option()

def update_staff():

print("****************************WELCOME TO LIBRARY MANAGEMENT


SYSTEM*****************************")

print("****************************FILL THE DETAILS YOU WANT TO UPDATE


***********************************")

ID=int(input("ENTER STAFF ID:"))

Name=input("ENTER STAFF NAME:")

Address=input("ENTER STAFF ADDRESS:")

Gender=input("ENTER STAFF GENDER:")

Phone_no=int(input ("ENTER STAFF PHONE NO:"))

Branch_ID=int(input("ENTER BRANCH ID:"))


cur_obj=con_obj.cursor()

data="update staff set


Staff_Name='{}',Staff_Address='{}',Staff_Gender='{}',Staff_Phon_no={},Branch_ID={} where
Staff_ID={}".format(ID,Name,Address,Gender,Phone_no,Branch_ID)

cur_obj.execute(data)

con_obj.commit()

print('*'*500)

print('*'*500)

print('*'*500)

print("STAFF DETAILS HAS BEEN UPDATED")

option()

def delete_staff():

print("**********WELCOME TO LIBRARY MANAGEMENT SYSTEM*************")

print("**********ENTER THE DETAILS YOU WANT TO DELETE***************")

ID=int(input("Enter Staff Id:"))

cur_obj=con_obj.cursor()

data="delete from staff where Staff_ID={}".format(ID)

cur_obj.execute(data)

con_obj.commit()

print('*'*500)
print('*'*500)

print('*'*500)

print("STAFF DETAILS HAS BEEN DELETED")

option()

def search_satff():

print("******************WELCOME TO LIBRARY MANAGEMENT SYSTEM****************")

print("**************ENTER THE DETAILS YOU WANT TO SEARCH****************")

ID=int(input("Enter Staff ID:"))

cur_obj=con_obj.cursor()

data="select * from staff where Staff_ID={}".format(ID)

cur_obj.execute(data)

row=cur_obj.fetchall()

print(row)

con_obj.close()

print('*'*500)

print('*'*500)

print('*'*500)

print("STAFF DETAILS HAS BEEN SEARCHED SUCESSFULLY")

option()

def display_staff():

print("*********************WELCOME TO LIBRARY MANAGEMENT


SYSTEM*******************")
print("**********************DISPLAY DETAILS OF ALL THE
BOOKS***************************")

data="select * from staff"

cur_obj.execute(data)

row=cur_obj.fetchall()

print(row)

con_obj.close()

print('*'*500)

print('*'*500)

print('*'*500)

print("DETAILS OF ALL THE BOOKS HAS BEEN DISPLAYED SUCESSFULLY")

option()

def option():

print(""" LIBRARY MANAGEMENT

OPTIONS

1 INSERT BOOKS

2 UPDATE BOOKS

3 DELETE BOOKS

4 SEARCH BOOKS

5 DISPLAY BOOKS
6 INSERT BRANCH

7 UPDATE BRANCH

8 DELETE BRANCH

9 SEARCH BRANCH

10 DISPLAY BRANCH

11 INSERT CUSTOMER

12 UPDATE CUSTOMER

13 DELETE CUSTOMER

14 SEARCH CUSTOMER

15 DISPLAY CUSTOMER

16 INSERT ISSUE BOOK

17 UPDATE ISSUE BOOK

18 DELETE ISSUE BOOK

19 SEARCH ISSUE BOOK

20 DISPLAY ISSUE BOOK

21 INSERT RETURN BOOK

22 UPDATE RETURN BOOK

23 DELETE RETURN BOOK

24 SEARCH RETURN BOOK

25 DISPLAY RETURN BOOK

26 INSERT STAFF

27 UPDATE STAFF

28 DELETE STAFF

29 SEARCH STAFF

30 DISPLAY STAFF
31 LOG OUT

""")

ch=int(input('Enter your option :'))

print('<<<<--------------------------------------------------------------------->>>>')

if ch==1:

insert_book()

elif ch==2:

update_book()

elif ch==3:

delete_book()

elif ch==4:

search_book()

elif ch==5:

display_book()

elif ch==6:

insert_branch()

elif ch==7:

update_branch()

elif ch==8:

delete_branch()

elif ch==9:

search_branch()
elif ch==10:

display_branch()

elif ch==11:

insert_customer()

elif ch==12:

update_customer()

elif ch==13:

delete_customer()

elif ch==14:

search_customer()

elif ch==15:

display_customer()

elif ch==16:

insert_issuebook()

elif ch ==17:

update_issuebook()

elif ch==18:

delete_issuebook()

elif ch==19:

search_issuebook()

elif ch==20:

display_issuebook()

elif ch==21:

insert_returnbook()

elif ch==22:
update_returnbook()

elif ch==23:

delete_returnbook()

elif ch==24:

search_returnbook()

elif ch==25:

display_returnbook()

elif ch==26:

insert_staff()

elif ch==27:

update_staff()

elif ch==28:

delete_staff()

elif ch==29:

search_staff()

elif ch==30:

display_staff()

elif ch==31:

print("LOG OUT")

else:

print("INVALID CHOICE")

option()
def log_in():

print("*************WELCOME TO LIBRARY MANAGEMENT SYSTEM************** ")

user=input(' Enter username :')

passwd=input(' Enter passwd :')

if user!='acv1942':

print('check you user name')

log_in()

elif passwd!='py1942':

print('Wrong passwd')

lon_in()

else:

option()

log_in()

You might also like