Employee Project

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

def databasecreation():

import mysql.connector as m
conn=m.connect(host="localhost",user="root",passwd="ram@1982")
cur=conn.cursor()
cur.execute("create database if not exists company;")
conn.close()
def tousedatabase():
import mysql.connector as m

conn=m.connect(host="localhost",user="root",passwd="ram@1982",database="company")
cur=conn.cursor()
cur.execute("use company")
conn.close()
def empdetails():
import mysql.connector as m

conn=m.connect(host="localhost",user="root",passwd="ram@1982",database="company")
cur=conn.cursor()
cur.execute("create table if not exists employees(empno int,birthdate
date,firstname varchar(30),lastname varchar(30),gender char(1),hire_date date);")
conn.close()
def insertdetails():
import mysql.connector as m

conn=m.connect(host="localhost",user="root",passwd="ram@1982",database="company")
cur=conn.cursor()
c="y"
while c=="y" or c=="Y":
eno=int(input("Enter the Empno:"))
bdate=input("Enter date:")
f_name=input("Enter the first name:")
l_name=input("Enter the lastname:")
gend=input("Enter the gender:")
h_date=input("Enter the hiredate:")
q="insert into
employees(empno,birthdate,firstname,lastname,gender,hire_date)values({},'{}','{}','
{}','{}','{}')".format(eno,bdate,f_name,l_name,gend,h_date)
cur.execute(q)
conn.commit()
c=input("Do you want to continue........ (y/n)")
conn.close()
def toshowemployees():
import mysql.connector as m

conn=m.connect(host="localhost",user="root",passwd="ram@1982",database="company")
cur=conn.cursor()
cur.execute("select * from employees;")
print("empno | dob | fname | lname | gender | hdate")
x=cur.fetchall()
for i in x:
print(i)
conn.close()
def updateemp():
import mysql.connector as m

conn=m.connect(host="localhost",user="root",passwd="ram@1982",database="company")
cur=conn.cursor()
empname=input("Enter the new name :")
q="update employees set firstname='{}' where empno=56;".format(empname)
cur.execute(q)
conn.commit()
conn.close()
def main():
c="y"
while c=="y" or c=="Y":
print("************************************Employee Management
System****************************************************************")
print()
print()
print(" Welcome you all")
print()
print()
print()
print()
print("1.To view employee details")
print()
print("2. To input the values in the table")
print()
print("3. To update the firstname")
print()
print("4. To Exit")
print()
x=int(input("Enter your choice:"))
if x==1:
toshowemployees()

elif x==2:
insertdetails()

elif x==3:
updateemp()

elif x==4:
break

c=input("Need to go back to main menu.....(y/N)")


print("*****************************************Thank
you****************************************************************************")

main()

You might also like