0% found this document useful (0 votes)
3 views3 pages

SQL

The document is a Python script for a Hospital Management System that connects to a MySQL database. It allows users to add, show, search, and delete patient records through a command-line interface. The script includes functions for each operation and a menu for user interaction.

Uploaded by

netflixmishan2
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)
3 views3 pages

SQL

The document is a Python script for a Hospital Management System that connects to a MySQL database. It allows users to add, show, search, and delete patient records through a command-line interface. The script includes functions for each operation and a menu for user interaction.

Uploaded by

netflixmishan2
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

import mysql.

connector

con = [Link](

host="localhost",

user="root",

passwd="root",

database="HospitalDB"

cur = [Link]()

def add_patient():

pid = int(input("Enter Patient ID: "))

name = input("Enter Name: ")

age = int(input("Enter Age: "))

gender = input("Enter Gender (M/F): ")

disease = input("Enter Disease: ")

did = int(input("Enter Doctor ID: "))

query = "INSERT INTO Patient VALUES (%s,%s,%s,%s,%s,%s)"

[Link](query, (pid, name, age, gender, disease, did))

[Link]()

print("Patient Added Successfully!")

def show_patients():

[Link]("SELECT * FROM Patient")

for row in [Link]():

print(row)
def search_patient():

pid = int(input("Enter Patient ID to Search: "))

[Link]("SELECT * FROM Patient WHERE PatID=%s", (pid,))

for row in [Link]():

print(row)

def delete_patient():

pid = int(input("Enter Patient ID to Delete: "))

[Link]("DELETE FROM Patient WHERE PatID=%s", (pid,))

[Link]()

print("Record Deleted Successfully!")

while True:

print("\n--- HOSPITAL MANAGEMENT MENU ---")

print("1. Add Patient")

print("2. Show Patients")

print("3. Search Patient")

print("4. Delete Patient")

print("5. Exit")

choice = int(input("Enter Choice: "))

if choice == 1:

add_patient()

elif choice == 2:

show_patients()

elif choice == 3:
search_patient()

elif choice == 4:

delete_patient()

elif choice == 5:

break

else:

print("Invalid Choice!")

OUTPUT

--- HOSPITAL MANAGEMENT MENU ---

1. Add Patient

2. Show Patients

3. Search Patient

4. Delete Patient

5. Exit

Enter Choice: 2

(101, 'Ravi Kumar', 35, 'M', 'Heart Pain', 1)

(102, 'Sita Das', 28, 'F', 'Migraine', 2)

(103, 'Amit Roy', 45, 'M', 'Fracture', 3)

You might also like