The project is about employee management system. The language used in this project is Perl and MySql database for storing data with phpMyadmin as database handler.
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Miniproject on Employee Management using Perl/Database.
1. EMPLOYEE MANAGEMENT SYSTEM
Mini-Project Report submitted in partial fulfilment of the requirements of the degree of Second
Year of Engineering by
Sanchit Raut - 46
Rohit Pujari – 44
Vaibhav Patel - 34
Department of Computer Engineering
St. John College of Engineering and Management
University of Mumbai
2017-2018
2. Abstract
Employee management is handy for organization for business tools for convinent information
storing which is easily accessible. By this system burden of managing and viewing employee
information is reduced.
This system is flexible and can be run on almost all major Operating systems like windows, linux
and mac.
3. Introduction
The organization are suffering from pity bad condition. Carrying heavy diaries to maintain
records and managing their salaries is a very tough job. To overcome these problems, we are
proposing “EMPLOYEE MANAGEMENT SYSTEM”. This app is very simple and easy to use.
Management team can add details of the Employees. It can store all details like name,
address, telephone number, their role, date of joining, salaries etc. of Employees.
All the data is stored in the database so there is no worry of Data Loss. The Data can be
accessed using Database manager (phpMyAdmin).
4. Implementation
Modules used :
use DBI :
- It is a database access module for the Perl programming language. (Database
Independent Interface)
- Program is connected to database using this DBI module.
- During connection it will do a authentication check.
my $dsn = "DBI:mysql:Employee";
my $username = "root";
my $password = "mysql";
my $dbh = DBI->connect($dsn, $username, $password) or die "Connection failed.Please Check
Username and Password $!";
print("Connected To Database Successfully.n");
Here $dsn is the host, where Employee is the name of the database.
If the authentication failed due to some reason such as invalid Username or Password it will
execute the die() function notifying the error message.
5. Database (MySQL):
My Sql database is used for collecting the employees information and storing it to the
database.
Queries:
Inserting :
my $sql = "INSERT INTO Data(ID, NAME, ADDRESS, PHONE_NO,
DATE_OF_JOINING, ROLE_ASSIGN, SALARY)VALUES(?,?,?,?,?,?,?)"
Here, ‘Insert into Data’ is used to insert information into table where ‘Data’ is the name of
the table.‘?’ binds the Index parameters coloumnwise.
Viewing all employees :
my $sql = "SELECT * FROM Data";
This query displays all the data available in the database table.
Viewing single employee(Single row):
my $var = $dbh->quote($ID);
For this at first User input is taken from user.The value of ID is then stored in the variable
“$var”. quote() function is used to fetch the user value which is stored in $ID.
my @row;
while (@row = $sth->fetchrow_array)
{
print join(", ", @row), "n";
}
fetchrow_arrow get the whole row from the table where ID is <STDIN>.
Removing all rows:
my $sql = "TRUNCATE TABLE Data";
Truncate Table Data is the query to flush all the rows from the table.
Removing a single employee :
my $sql = "DELETE FROM Data WHERE ID = ?"
Delete query will delete a single row from the table where ID is <STDIN>(User value).
Update Employe data :
my $sql = "UPDATE Data SET NAME = ?, ADDRESS=?, PHONE_NO=?,
DATE_OF_JOINING=?, ROLE_ASSIGN=?, SALARY=? WHERE ID = ?";
6. It will Update the data and replace(SET) the new value to it as user give the input.
bind_param() :
bind parameters binds the scalar value fetched from user which is then updated in database
table.
$dbh :
Databasehandler is used to specify the DBI dsn (“connect in DBI”) as a hash reference
instead of a string.
7. Code
To create database table
#!usrbinperl
use warnings;
use strict;
use DBI;
my ($dbh, $sth);
$dbh=DBI->connect('dbi:mysql:Employee','root','mysql') ||
die "Error opening database: $DBI::errsn";
$sth=$dbh->prepare("CREATE TABLE Data (
ID INTEGER , NOT NULL
NAME VARCHAR(32) NOT NULL,
ADDRESS VARCHAR(32) NOT NULL,
PHONE_NO VARCHAR(32),
DATE_OF_JOINING VARCHAR(32) NOT NULL,
ROLE_ASSIGN VARCHAR(32) NOT NULL,
SALARY INTEGER)");
$sth->execute();
$sth->finish();
print "n Table created in database Employeen";
$dbh->disconnect || die "Failed to disconnectn";
8. Main code
#!/usr/bin/perl
use warnings;
use strict;
use DBI;
#Connecting to Database.
my $dsn = "DBI:mysql:Employee";
my $username = "root";
my $password = "mysql";
my $dbh = DBI->connect($dsn, $username, $password);
print("Connected To Database Successfully.n");
#Insert into Database.
sub insert
{
my $sql = "INSERT INTO Data(ID, NAME, ADDRESS, PHONE_NO,
DATE_OF_JOINING, ROLE_ASSIGN, SALARY)
VALUES(?,?,?,?,?,?,?)";
my $stmt = $dbh->prepare($sql);
my @employee = get_details();
foreach my $employee(@employee)
11. my $var = $dbh->quote($ID);
my $sql = "SELECT * FROM Data WHERE ID = $var";
my $sth = $dbh->prepare($sql) or die $DBI::errs;
$sth->execute() or die $DBI::errs;
my @row;
while (@row = $sth->fetchrow_array)
{
print join(", ", @row), "n";
}
#$sth->finish();
}
#Get Details of all Employee
sub view_all
{
my ($dbh) = @_;
my $sql = "SELECT * FROM Data";
my $sth = $dbh->prepare($sql) or die $DBI::errs;
$sth->execute() or die $DBI::errs;
$sth->dump_results();
$sth->finish();
12. }
#Update an Employee
sub update
{
my $sql = "UPDATE Data SET NAME = ?, ADDRESS=?, PHONE_NO=?,
DATE_OF_JOINING=?, ROLE_ASSIGN=?, SALARY=? WHERE ID = ?";
my $sth = $dbh->prepare($sql);
print("Enter ID to update : ");
chomp(my $ID = <STDIN>);
print("n");
print("NAME : ");
chomp(my $NAME = <STDIN>);
print("ADDRESS : ");
chomp(my $ADDRESS = <STDIN>);
print("PHONE_NO : ");
chomp(my $PHONE_NO = <STDIN>);
print("DATE_OF_JOINING : ");
chomp(my $DATE_OF_JOINING = <STDIN>);
13. print("ROLE_ASSIGN : ");
chomp(my $ROLE_ASSIGN = <STDIN>);
print("SALARY : ");
chomp(my $SALARY = <STDIN>);
$sth->bind_param(1,$NAME);
$sth->bind_param(2,$ADDRESS);
$sth->bind_param(3,$PHONE_NO);
$sth->bind_param(4,$DATE_OF_JOINING);
$sth->bind_param(5,$ROLE_ASSIGN);
$sth->bind_param(6,$SALARY);
$sth->bind_param(7,$ID);
$sth->execute();
print("n The record has been updated successfully! n");
$dbh->{mysql_auto_reconnect} = 1;
$sth->finish();
$dbh->disconnect();
}
#Delete single Employee
sub delete_one_row
{
14. my $sql = "DELETE FROM Data WHERE ID = ?";
my $sth = $dbh->prepare($sql);
print "Enter ID to remove : ";
chomp(my $ID = <STDIN>);
$sth->execute($ID);
print "ID no.$ID has been deleted successfully";
$dbh->{mysql_auto_reconnect} = 1;
$dbh->disconnect();
}
#Deletes all Employee
sub delete_all_rows
{
my($dbh) = @_;
my $sql = "TRUNCATE TABLE Data";
my $sth = $dbh->prepare($sql);
return $sth->execute();
}
#multi-line print() Function
sub menu
{
print <<EOT;
15. Please make a choice :
1. Add an Employee.
2. View an Employee.
3. View all Employee.
4. Update an Employee.
5. Remove an Employee.
6. Remove all Employee.
7. Exit.
Your Choice :
EOT
}
#Select Options
while(1)
{
menu();
chomp(my $answer = <STDIN>);
SWITCH: {
$answer == 1 and insert(), last SWITCH;
$answer == 2 and view_one(), last SWITCH;
$answer == 3 and view_all($dbh), last SWITCH;
$answer == 4 and update(), last SWITCH;
$answer == 5 and delete_one_row(), last SWITCH;
$answer == 6 and delete_all_rows($dbh), last SWITCH;
$answer == 7 and exit(0);
}
17. Conclusion
The project aims at bringing simplicity of the system such as by using this program to show details
in a well organized manner and with ease. In future this system can be extended to integrate more
modules and features. Provisions can be made in future so that much better GUI can be provided
to all the user of the system.
References
1. http://www.mysqltutorial.org
2. https://www.tutorialspoint.com/perl/index.htm
3. Programming the Perl DBI – O’REILLY