0% found this document useful (0 votes)
59 views18 pages

0996 HKK

This document describes a Python program that interfaces with a MySQL database to manage employee data. The program allows users to perform CRUD (create, read, update, delete) operations on an employee table within the database. Functions are defined to create the database, insert, search, update, and delete employee records from the table. The search function allows searching by employee ID, name, or salary. The output demonstrates sample interactions with the menu-driven program, including creating the database, inserting data, and searching/updating records. References used in developing the program are also listed.

Uploaded by

Max Robert
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
59 views18 pages

0996 HKK

This document describes a Python program that interfaces with a MySQL database to manage employee data. The program allows users to perform CRUD (create, read, update, delete) operations on an employee table within the database. Functions are defined to create the database, insert, search, update, and delete employee records from the table. The search function allows searching by employee ID, name, or salary. The output demonstrates sample interactions with the menu-driven program, including creating the database, inserting data, and searching/updating records. References used in developing the program are also listed.

Uploaded by

Max Robert
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

EMPLOYEE MANAGEMENT

A Project Report Submitted In


COMPUTER SCIENCE (083)

Done By:
Name: Hamza Khan
Reg. No:
CERTIFICATE

It is certified that the work contained in the project titled


"EMPLOYEE MANAGEMENT" by "Hamza Khan" has been carried out
under my supervision as prescribed by the CBSE.

Internal Examiner External Examiner

Principal
ACKNOWLEDGEMENT

Apart from the efforts of myself, the success of any


project depends largely upon the encouragement and
guidelines of many others. I wish to express my deep
gratitude and sincere thanks to Supervisor Jyothi K,
principal Ms. Tabassum Farooqui, New Middle East
International School, Riyadh, for their encouragement and
for all the facilities that they provided in this project work.
I extent my hearty thanks to Asha Mariam Itty, Computer
Science teacher, who guided me to the successful
completion of this project. Finally, I thank my family
members for help and successful completion of this
project.
Contents

Sr NO Name Page

1 About Python and MySQL

2 About The Project

3 Python Code

4 Output

5 References
About Python and MySQL

Python:
Python is a computer programming language often used to
build websites and software, automate tasks, and conduct
data analysis. Python is a general-purpose language,
meaning it can be used to create a variety of different
programs and isn’t specialized for any specific problems.

Python is commonly used for developing websites and


software, task automation, data analysis, and data
visualization.

Since it’s relatively easy to learn, Python has been adopted


by many non-programmers such as accountants and
scientists, for a variety of everyday tasks, like organizing
finances.
MySQL:
MySQL is an open-source relational database management
system (RDBMS). Its name is a combination of "My", the
name of co-founder Michael Widenius's daughter My and
"SQL", the abbreviation for Structured Query Language.

A relational database organizes data into one or more


data tables in which data may be related to each other;
these relations help structure the data. SQL is a language
programmers use to create, modify and extract data from
the relational database, as well as control user access to
the database.

In addition to relational databases and SQL, an RDBMS


like MySQL works with an operating system to implement
a relational database in a computer's storage system,
manages users, allows for network access and facilitates
testing database integrity and creation of backups.
About the Project

The aim of this project is to create a Python-SQL interfaced data


management system with Insert, Search, Update, Delete and Display
being the key operations along with searching the data by 3 different
ways ( name, id, salary )
Database Name: employee
Table Name: emp
The table "emp" mentioned consists of three fields, "ID", "Name",
"Salary" .
A brief information of each field is as follows:
ID (Employee Code): Code of the employee.
Name (Employee Name): Name of the employee.
Salary: Employee's Salary.
Python Code

import mysql.connector as driver

import sys

def menu():

loop='y'

while(loop=='y' or loop=='Y'):

print("........MENU.......")

print("1. CREATE DATABASE")

print("2. SHOW DATABASES")

print("3. SHOW TABLES")

print("4. INSERT RECORD")

print("5. UPDATE RECORD")

print("6. DELETE RECORD")

print("7. SEARCH RECORD")

print("8. DISPLAY RECORD")

print()

print()

choice=int(input("Enter the choice (1-8) : "))

if(choice==1):

create_database()

elif(choice==2):

show_databases()

elif(choice==3):

show_tables()
elif(choice==4):

insert_record()

elif(choice==5):

update_record()

elif(choice==6):

delete_record()

elif(choice==7):

search_record()

elif(choice==8):

display_record()

else:

print("Wrong Choice.")

loop=input("Press 'y' to continue...")

else:

sys.exit()

def create_database():

con=driver.connect(host='localhost',user='root', passwd='hamzaA123')

if con.is_connected():

print("Successfully Connected")

cur=con.cursor()

cur.execute('create database if not exists employee')

print()

print("Database Created")

con.close()
def show_databases():

con=driver.connect(host='localhost',user='root',passwd='hamzaA123')

if con.is_connected():

print("Successfully Connected")

cur=con.cursor()

cur.execute('show databases')

for i in cur:

print(i)

con.close()

def show_tables():

con=driver.connect(host='localhost',user='root',passwd='hamzaA123',database='employee')

if con.is_connected():

print("Successfully Connected")

cur=con.cursor()

cur.execute('show tables')

for i in cur:

print(i)

con.close()

def insert_record():

con=driver.connect(host='localhost',user='root',passwd='hamzaA123',database='employee')

if con.is_connected():

print("Successfully Connected")

cur=con.cursor()

ID=int(input("ENTER EMPLOYEE ID : "))


NAME=input("ENTER NAME OF EMPLOYEE : ")

SALARY=float(input("ENTER EMPLOYEE SALARY : "))

query1="INSERT INTO emp(id,ename,salary) VALUES({},'{}',{})".format(ID,NAME,SALARY)

cur.execute(query1)

con.commit()

print('Record Inserted')

con.close()

else:

print("Error : Not Connected")

def update_record():

con=driver.connect(host='localhost',user='root',passwd='hamzaA123',database='employee')

cur=con.cursor()

d=int(input("Enter Employee ID for update record : "))

ID=int(input("ENTER NEW EMPLOYEE ID : "))

name=input("ENTER NEW NAME OF EMPLOYEE : ")

salary=float(input("ENTER NEW SALARY FOR EMPLOYEE : "))

query1="update emp set id=%s, ename='%s', salary=%s where id=%s" %(ID,name,salary,d)

cur.execute(query1)

con.commit()

print("Record Updated")

con.close()

def delete_record():

con=driver.connect(host='localhost',user='root',passwd='hamzaA123',database='employee')

cur=con.cursor()
d=int(input("Enter Employee ID for deleting record : "))

query1="delete from emp where id={0}".format(d)

cur.execute(query1)

con.commit()

print("Record Deleted")

con.close()

def search_record():

con=driver.connect(host='localhost',user='root',passwd='hamzaA123',database='employee')

cur=con.cursor()

print("ENTER THE CHOICE ACCORDING TO YOU WANT TO SEARCH RECORD: ")

print("1. ACCORDING TO ID")

print("2. ACCORDING TO NAME")

print("3. ACCORDING TO SALARY")

print()

choice=int(input("ENTER THE CHOICE (1-3) : "))

if choice==1:

d=int(input("Enter Employee ID which you want to search : "))

query1="select * from emp where id=%s" %(d)

elif choice==2:

name=input("Enter Employee Name which you want to search : ")

query1="select * from emp where ename='%s'" %(name)

elif choice==3:

sal=float(input("Enter Employee Salary which you want to search : "))

query1="select * from emp where salary=%s" %(sal)

else:
print("Wrong Choice")

cur.execute(query1)

rec=cur.fetchall()

count=cur.rowcount

print("Total no. of records found : ",count)

for i in rec:

print(i)

print("Record Searched")

con.close()

def display_record():

con=driver.connect(host='localhost',user='root',passwd='hamzaA123',database='employee')

if con.is_connected():

print("Successfully Connected")

cur=con.cursor()

cur.execute('select * from emp')

rec=cur.fetchall()

count=cur.rowcount

print("+----------|--------------|-----------+")

print("+ Emp ID | Emp Name | Salary |")

print("+----------|--------------|-----------+")

for i in rec:

print('|{0:^9} | {1:12} | {2:10}|'.format(i[0],i[1],i[2]))

print("+----------|--------------|-----------+")

print("+ Total no. of records are : ",count," |")

print("+-------------------------------------+")
for i in rec:

print(i)

con.close()

else:

print("Error : Database Connection is not success" )

menu()
Outputs:
1. Menu

2. Creation of database

3. Connecting and displaying the databases


4. Tables in the database (database used is employee)

5. Insertion of data

6. Displaying the data

7. Updating of data
8. Searching the data

( data can be searched by three ways using this program )

9. Deletion of data
References

 www.stackoverflow.com
 www.learnpython.org
 www.geeksforgeeks.org
 Computer Science Grade 12 CBSE Textbook (Sumita
Arora)

You might also like