Share & Revise Any Time

Related Posts


CREATE DATABASE USING MYSQL


import mysql.connector as a
con = a.connect(host="localhost",
              user="root",
              passwd="12345")
c = con.cursor()
sql1 = "create database employee"
c.execute(sql1)
sql2 = "use employee"
c.execute(sql2)
sql3 = "create table personal (name varchar(50),city varchar(20), dob varchar(20), phone varchar(20))"
c.execute(sql3)
sql4 = "create table office (ecode varchar(10),name varchar(50), post varchar(20), jdate varchar(20),basicpay int)"
c.execute(sql4)
sql5 = "create table salary (ecode varchar(10), name varchar(50), year varchar(10), month varchar(20), wdays int, tdays int)"
c.execute(sql5)
con.commit()

CREATE PROJECT INTERFACE USING PYTHON


import mysql.connector as a
con = a.connect(host="localhost",
              user="root",
              passwd="12345",
              database="employee")

def npersonal():
    n = input("Enter Employee Name : ")
    c = input("Enter Employee's City Name : ")
    d = input("Enter Employee's D.O.B : ")
    p = input("Enter Employee Phone : ")
    data = (n,c,d,p)
    sql = 'insert into personal values(%s,%s,%s,%s)'
    c = con.cursor()
    c.execute(sql,data)
    con.commit()
    print("Data Entered Successfully")
    main()

def personal():
        sql = "select * from personal"
        c = con.cursor()
        c.execute(sql)
        d = c.fetchall()
        for i in d:
            print(i)
        main()
    
def noffice():
    ec = input("Enter Employee Code : ")
    n = input("Enter Employee Name : ")
    ps = input("Enter Employee's Post : ")
    j = input("Enter Employee's joining date : ")
    bp = int(input("Enter Assigned Salary : "))
    data = (ec,n,ps,j,bp)
    sql = 'insert into office values(%s,%s,%s,%s,%s)'
    c = con.cursor()
    c.execute(sql,data)
    con.commit()
    print("Data Entered Successfully")
    main()

def office():
        sql = "select * from office"
        c = con.cursor()
        c.execute(sql)
        d = c.fetchall()
        for i in d:
            print(i)
        main()
    
def nsalary():
    ec = input("Enter Employee Code : ")
    v = (ec,)
    sql = "select BasicPay from office where Ecode = %s"
    c = con.cursor( )
    c.execute(sql,v)
    bs = c.fetchone( )  # (30000,)
    n = input("Enter Employee Name : ")
    y = input("Enter Year : ")
    m = input("Enter Month : ")
    wd = int(input("Enter working Days : "))
    td = int(input("Enter Total Days : "))
    fp = bs[0]/td*wd
    data = (ec,n,y,m,wd,fp)
    sql = 'insert into salary values(%s,%s,%s,%s,%s,%s)'
    c = con.cursor()
    c.execute(sql,data)
    con.commit()
    print("Data Entered Successfully")
    main()

def salary():
        sql = "select * from salary"
        c = con.cursor()
        c.execute(sql)
        d = c.fetchall()
        for i in d:
            print(i)
        main()
        
def main():
    print("""
    1. Add New Employee Personal Details
    2. Display Employees Personal Details
    3. Add New Employee Office Details
    4. Display Employees Office Details
    5. Enter Salary Details of Employee
    6. Display Salary Details of Employee""")
    choice = input("Enter Task No : ")
    while True:
        if (choice == '1'): 
            npersonal()
        elif (choice=='2'): 
            personal() 
        elif (choice=='3'): 
            noffice() 
        elif (choice=='4'): 
            office()
        elif (choice=='5'): 
            nsalary()
        elif (choice == '6'):
            salary()
        else: 
            print(" Wrong choice..........") 
main()

Share & Revise Any Time