Code for Employee Management System
Code for Employee Management System
Code for Employee Management System
Then, run the code below to create the Employee Management System.
import mysql.connector
db = mysql.connector.connect(
host="localhost",
user="yourusername",
password="yourpassword",
database="employee_db"
cursor = db.cursor()
cursor.execute("USE employee_db")
cursor.execute("""
age INT,
department VARCHAR(255),
salary FLOAT
""")
cursor.execute(query, values)
db.commit()
def display_employees():
employees = cursor.fetchall()
print("ID\tName\t\tAge\tDepartment\tSalary")
print("-" * 50)
values = []
if name:
values.append(name)
if age:
values.append(age)
if department:
values.append(department)
if salary:
values.append(salary)
values.append(emp_id)
cursor.execute(query, tuple(values))
db.commit()
def delete_employee(emp_id):
cursor.execute(query, (emp_id,))
db.commit()
# Example Usage
display_employees()
delete_employee(3)
display_employees()
db.close()
—---------------------------------------------------------------------
Examples