import pymysql
db = pymysql.connect(
host="127.0.0.1",
user="root",
password="ganesh",
database="practical5"
)
cursor = db.cursor() #DATABASE KE SATH INTERACTIN KELIYE
while True:
print("\nDatabase Navigation Operations:")
print("1. Add Record")
print("2. Delete Record")
print("3. Update Record")
print("4. Exit")
choice = input("Enter your choice (1/2/3/4): ")
if choice == "1":
emp_name = input("Enter Employee Name: ")
emp_id = input("Enter Employee ID: ")
salary = input("Enter Salary: ")
sql = "INSERT INTO employee (EMP_NAME, EMP_ID, SALARY) VALUES (%s, %s, %s)"
cursor.execute(sql, (emp_name, emp_id, salary))
db.commit()
print("Record added successfully.")
elif choice == "2":
emp_id = input("Enter Employee ID to delete: ")
sql = "DELETE FROM employee WHERE EMP_ID = %s"
cursor.execute(sql, (emp_id,))
db.commit()
print("Record deleted successfully.")
elif choice == "3":
emp_id = input("Enter Employee ID to update: ")
attribute = input("Enter the attribute to update(EDIT) (EMP_NAME, EMP_ID, SALARY): ")
new_value = input("Enter the new value for {}: ".format(attribute))
sql = "UPDATE employee SET {} = %s WHERE EMP_ID = %s".format(attribute)
cursor.execute(sql, (new_value, emp_id))
db.commit()
print("Record updated successfully.")
elif choice == "4":
break
else:
print("Invalid choice. Please enter a valid option.")
db.close()
#GANESH