Librarymgmt
Librarymgmt
Acknowledgement
certificate
Intriduction of project
Source Code
import mysql.connector
def connect_to_db():
return mysql.connector.connect(
def add_book():
connection = connect_to_db()
cursor = connection.cursor()
cursor.execute("""
connection.commit()
cursor.close()
connection.close()
# Add a new member
def add_member():
connection = connect_to_db()
cursor = connection.cursor()
cursor.execute("""
connection.commit()
cursor.close()
connection.close()
# Borrow a book
def borrow_book():
borrow_date = datetime.now().date()
connection = connect_to_db()
cursor = connection.cursor()
book = cursor.fetchone()
cursor.execute("""
UPDATE books
WHERE book_id = %s
""", (book_id,))
cursor.execute("""
connection.commit()
else:
cursor.close()
connection.close()
# Return a book
def return_book():
return_date = datetime.now().date()
connection = connect_to_db()
cursor = connection.cursor()
transaction = cursor.fetchone()
if transaction:
book_id = transaction[0]
cursor.execute("""
UPDATE books
WHERE book_id = %s
""", (book_id,))
cursor.execute("""
UPDATE transactions
SET return_date = %s
WHERE transaction_id = %s
connection.commit()
else:
cursor.close()
connection.close()
def view_books():
connection = connect_to_db()
cursor = connection.cursor()
books = cursor.fetchall()
print(f"ID: {book[0]}, Title: {book[1]}, Author: {book[2]}, Year: {book[3]}, Genre: {book[4]}, Quantity: {book[5]}")
cursor.close()
connection.close()
def view_members():
connection = connect_to_db()
cursor = connection.cursor()
members = cursor.fetchall()
print("Library Members:")
cursor.close()
connection.close()
def main():
while True:
print("7. Exit")
if choice == "1":
add_book()
add_member()
borrow_book()
view_books()
view_members()
break
else:
if __name__ == "__main__":
main()
SQL DATABASE:
-- Create database
USE LibraryDB;
genre VARCHAR(100),
);
first_name VARCHAR(100),
last_name VARCHAR(100),
phone VARCHAR(15)
);
book_id INT,
member_id INT,
borrow_date DATE,
return_date DATE,
);