LIBRARY MANAGEMENT 1
LIBRARY MANAGEMENT 1
DEVELOPED BY SUBMITTED TO
SHAGUN DUBEY POOJA KHARE
XII E
28
P a g e 1 | 24
LIBRARY MANAGEMENT | SHAGUN DUBEY
CERTIFICATE
This is to certify that SHAGUN DUBEY of class XII E of
PM SHRI KENDRIYA VIDYALAYA NFC VIGYAN VIHAR has
completed her project on “SCHOOL MANAGEMENT
SYSTEM” under my supervision. She has shown great
interest and sincerity in completing this project.
_________________ __________________
INTERNAL EXAMINER EXTERNAL EXAMINER
P a g e 2 | 24
LIBRARY MANAGEMENT | SHAGUN DUBEY
ACKNOWLEDGEMENT
P a g e 3 | 24
LIBRARY MANAGEMENT | SHAGUN DUBEY
INDEX
SNO CONTEXT PAGE
NO
LIBRARY MANAGEMENT
INTRODUCTION
1. AIM 5-7
IMPLEMENTATION
NEED
SOURCE CODE
2. 8-19
OUTPUT
3. 19-24
4. REQUIRED MATERIALS 25
5. BIBLIOGRAPHY
26
P a g e 4 | 24
LIBRARY MANAGEMENT | SHAGUN DUBEY
1. Database Creation:
A MySQL database is created with tables for storing information about books, users, and
transactions. The key tables include:
• Books: Contains details like Book ID, title, author, publication year, and
availability.
• Users: Maintains records of library members, including User ID, name, and
contact information.
• Transactions: Tracks book issues and returns with timestamps and user details.
2. Development of Features:
• Admin Features:
• Add, update, or delete books.
• View all books and users.
• Register new users.
• Librarian Features:
• Issue books to users.
• Return books and update availability.
• User Features (optional for future expansion):
• Search for books.
• View borrowed books and due dates.
3. Programming:
• Frontend: Uses Python for the command-line interface to interact with the
system.
• Backend: Python’s mysql.connector module connects the program to the
MySQL database for CRUD (Create, Read, Update, Delete) operations.
4. System Security:
Password-protected interfaces (e.g., Admin password) ensure restricted access to
critical operations.
P a g e 6 | 24
LIBRARY MANAGEMENT | SHAGUN DUBEY
6. Future Enhancements:
• Integration of a graphical user interface (GUI) for better usability.
• Online catalog access for remote users.
• SMS or email notifications for overdue books.
2. Time-Saving
Searching for books, tracking due dates, and managing users manually can be time-
consuming. An LMS provides instant access to information, saving time for both
librarians and users.
P a g e 7 | 24
LIBRARY MANAGEMENT | SHAGUN DUBEY
#CODE#
import mysql.connector as pymysql
from datetime import datetime
password = None
db = None
C = None
def base_check():
check = 0
db = pymysql.connect(host="localhost", user="root", password=passwrd)
cursor = db.cursor()
cursor.execute('SHOW DATABASES')
result = cursor.fetchall()
for r in result:
for i in r:
if i == 'library':
cursor.execute('USE library')
check = 1
if check != 1:
create_database()
def table_check():
db = pymysql.connect(host="localhost", user="root", password=passwrd)
cursor = db.cursor()
P a g e 8 | 24
LIBRARY MANAGEMENT | SHAGUN DUBEY
cursor.execute('SHOW DATABASES')
result = cursor.fetchall()
for r in result:
for i in r:
if i == 'library':
cursor.execute('USE library')
cursor.execute('SHOW TABLES')
result = cursor.fetchall()
if len(result) <= 2:
create_tables()
else:
print(' Booting systems...')
def create_database():
try:
db = pymysql.connect(host="localhost", user="root", password=passwrd)
cursor = db.cursor()
cursor.execute("CREATE DATABASE IF NOT EXISTS library")
db.commit()
db.close()
print("Database 'library' created successfully.")
except pymysql.Error as e:
print(f"Error creating database: {str(e)}")
def create_tables():
try:
P a g e 9 | 24
LIBRARY MANAGEMENT | SHAGUN DUBEY
cursor.execute("""
CREATE TABLE IF NOT EXISTS books (
BOOK_ID INT PRIMARY KEY,
TITLE VARCHAR(255),
AUTHOR VARCHAR(255),
YEAR INT,
AVAILABLE INT
)
""")
cursor.execute("""
CREATE TABLE IF NOT EXISTS users (
USER_ID INT PRIMARY KEY,
NAME VARCHAR(255),
PHONE_NO VARCHAR(15)
)
""")
cursor.execute("""
CREATE TABLE IF NOT EXISTS transactions (
TRANSACTION_ID INT AUTO_INCREMENT PRIMARY KEY,
USER_ID INT,
BOOK_ID INT,
P a g e 10 | 24
LIBRARY MANAGEMENT | SHAGUN DUBEY
ISSUE_DATE DATE,
RETURN_DATE DATE,
FOREIGN KEY (USER_ID) REFERENCES users(USER_ID),
FOREIGN KEY (BOOK_ID) REFERENCES books(BOOK_ID) ON DELETE CASCADE
)
""")
db.commit()
db.close()
print("Tables 'books', 'users', and 'transactions' created successfully.")
except pymysql.Error as e:
print(f"Error creating tables: {str(e)}")
def QR():
result = C.fetchall()
for r in result:
print(r)
def add_book():
book_id = int(input("Enter Book ID: "))
title = input("Enter Book Title: ")
author = input("Enter Author: ")
year = int(input("Enter Year of Publication: "))
available = int(input("Enter Number of Available Copies: "))
data = (book_id, title, author, year, available)
sql = "INSERT INTO books (BOOK_ID, TITLE, AUTHOR, YEAR, AVAILABLE) VALUES (%s, %s,
%s, %s, %s)"
P a g e 11 | 24
LIBRARY MANAGEMENT | SHAGUN DUBEY
try:
C.execute(sql, data)
db.commit()
print('Book added successfully...')
except pymysql.Error as e:
print(f"Error adding book: {str(e)}")
def view_books():
C.execute("SELECT * FROM books")
QR()
def update_book():
book_id = int(input("Enter Book ID to update: "))
field = input("Enter field to update [TITLE, AUTHOR, YEAR, AVAILABLE]: ")
new_value = input(f"Enter new value for {field}: ")
if field in ['YEAR', 'AVAILABLE']:
new_value = int(new_value)
sql = f"UPDATE books SET {field} = %s WHERE BOOK_ID = %s"
try:
C.execute(sql, (new_value, book_id))
db.commit()
print('Book updated successfully...')
except pymysql.Error as e:
print(f"Error updating book: {str(e)}")
def delete_book():
book_id = int(input("Enter Book ID to delete: "))
P a g e 12 | 24
LIBRARY MANAGEMENT | SHAGUN DUBEY
try:
sql_delete_transactions = "DELETE FROM transactions WHERE BOOK_ID = %s"
C.execute(sql_delete_transactions, (book_id,))
db.commit()
print('Book and related transactions deleted successfully...')
except pymysql.Error as e:
print(f"Error deleting book: {str(e)}")
def register_user():
user_id = int(input("Enter User ID: "))
name = input("Enter User Name: ")
phone_no = input("Enter User Phone Number: ")
data = (user_id, name, phone_no)
sql = "INSERT INTO users (USER_ID, NAME, PHONE_NO) VALUES (%s, %s, %s)"
try:
C.execute(sql, data)
db.commit()
print('User registered successfully...')
except pymysql.Error as e:
print(f"Error registering user: {str(e)}")
def view_users():
C.execute("SELECT * FROM users")
P a g e 13 | 24
LIBRARY MANAGEMENT | SHAGUN DUBEY
QR()
def issue_book():
user_id = int(input("Enter User ID: "))
book_id = int(input("Enter Book ID: "))
issue_date = datetime.now().date()
sql_check = "SELECT AVAILABLE FROM books WHERE BOOK_ID = %s"
C.execute(sql_check, (book_id,))
result = C.fetchone()
if result and result[0] > 0:
sql_issue = "INSERT INTO transactions (USER_ID, BOOK_ID, ISSUE_DATE) VALUES (%s,
%s, %s)"
try:
C.execute(sql_issue, (user_id, book_id, issue_date))
sql_update = "UPDATE books SET AVAILABLE = AVAILABLE - 1 WHERE BOOK_ID = %s"
C.execute(sql_update, (book_id,))
db.commit()
print('Book issued successfully...')
except pymysql.Error as e:
print(f"Error issuing book: {str(e)}")
else:
print("Book not available.")
def return_book():
user_id = int(input("Enter User ID: "))
book_id = int(input("Enter Book ID: "))
return_date = datetime.now().date()
P a g e 14 | 24
LIBRARY MANAGEMENT | SHAGUN DUBEY
def view_user_transactions():
user_id = int(input("Enter User ID: "))
try:
sql_issued = """
SELECT b.TITLE, t.ISSUE_DATE
FROM transactions t
JOIN books b ON t.BOOK_ID = b.BOOK_ID
WHERE t.USER_ID = %s AND t.RETURN_DATE IS NULL
"""
P a g e 15 | 24
LIBRARY MANAGEMENT | SHAGUN DUBEY
C.execute(sql_issued, (user_id,))
issued_books = C.fetchall()
sql_returned = """
SELECT b.TITLE, t.ISSUE_DATE, t.RETURN_DATE
FROM transactions t
JOIN books b ON t.BOOK_ID = b.BOOK_ID
WHERE t.USER_ID = %s AND t.RETURN_DATE IS NOT NULL
"""
C.execute(sql_returned, (user_id,))
returned_books = C.fetchall()
print("\nBooks Returned:")
if returned_books:
for book in returned_books:
print(f"Title: {book[0]}, Issue Date: {book[1]}, Return Date: {book[2]}")
else:
print("No books returned.")
except pymysql.Error as e:
print(f"Error fetching user transactions: {str(e)}")
P a g e 16 | 24
LIBRARY MANAGEMENT | SHAGUN DUBEY
def main():
global passwrd
passwrd = input("Enter password for MySQL: ")
base_check()
table_check()
global db, C
db = pymysql.connect(host="localhost", user="root", password=passwrd,
database="library")
C = db.cursor()
while True:
log = input("\nLogin as Admin (A) or Librarian (L). Press Q to quit: ").upper()
if log == "A":
p = input("Enter Admin Password: ")
if p == 'admin123':
print("Admin Login Successful!")
while True:
menu = input('''\nAdd Book: AB, View Books: VB, Update Book: UB, Delete Book:
DB, Exit: E: ''').upper()
if menu == 'AB':
add_book()
elif menu == 'VB':
view_books()
elif menu == 'UB':
P a g e 17 | 24
LIBRARY MANAGEMENT | SHAGUN DUBEY
update_book()
elif menu == 'DB':
delete_book()
elif menu == 'E':
break
else:
print("Incorrect Admin Password.")
elif log == "L":
print("Librarian Login Successful!")
while True:
menu = input('''\nRegister User: RU, View Users: VU, Issue Book: IB, Return Book:
RB, View User Transactions: VT, Exit: E: ''').upper()
if menu == 'RU':
register_user()
elif menu == 'VU':
view_users()
elif menu == 'IB':
issue_book()
elif menu == 'RB':
return_book()
elif menu == 'VT':
view_user_transactions()
elif menu == 'E':
break
elif log == "Q":
db.commit()
db.close()
P a g e 18 | 24
LIBRARY MANAGEMENT | SHAGUN DUBEY
print("Goodbye!")
break
else:
print("Invalid input. Please try again.")
if __name__ == '__main__':
main()
MAIN LOGIN
ADMIN LOGIN
ADMIN FUNCTIONS
ADD BOOKS
P a g e 19 | 24
LIBRARY MANAGEMENT | SHAGUN DUBEY
VIEW BOOK
UPDATE BOOK
DELETE BOOK
LIBRARIAN LOGIN
P a g e 20 | 24
LIBRARY MANAGEMENT | SHAGUN DUBEY
LIBRARIAN FUNCTIONS
REGISTER USER
VIEW USER
ISSUE BOOK
RETURN BOOK
P a g e 21 | 24
LIBRARY MANAGEMENT | SHAGUN DUBEY
VIEW TRANSACTIONS
TABLES FORMED
DESCRIPTION OF TABLES
P a g e 22 | 24
LIBRARY MANAGEMENT | SHAGUN DUBEY
P a g e 23 | 24
LIBRARY MANAGEMENT | SHAGUN DUBEY
BIBLIOGRAPHY
Textbook
Google
YouTube
Class notes
P a g e 24 | 24