Paste Search Dynamic
Recent pastes
employees
  1. <?php
  2. import mysql.connector as my
  3. mydb=my.connect(host='localhost',
  4.                 user="root",
  5.                 passwd='',
  6.                 database="ritika")
  7. if mydb:
  8.     print("connection succesful")
  9. else:
  10.     print("connections failed")
  11.  
  12. cur=mydb.cursor()
  13. try:
  14.     str="create table employe(first_name varchar(20),last_name varchar(20),empid_id int,sex varchar(1)"
  15.     cur.execute(str)
  16.     mydb.commit()
  17.     print("1 ROW INSERTED")
  18. except Exception as e:
  19.     print(e)
  20. mydb.close()
  21. import mysql.connector as db
  22. def insertdy(fname,lname,emp_id,age,sex):
  23.     mydb=db.connect(host='localhost',
  24.                 user="root",
  25.                 passwd='',
  26.                 database="ritika")
  27.     if mydb:
  28.         print
  29.         print("connection succesful")
  30.     else:
  31.         print("connections failed")
  32.     cur=mydb.cursor()
  33.     str="insert into employe(first_name,last_name,emp_id,age,sex) values('%s',' %s','%d',' %d', '%s')"
  34.     args=(fname,lname,emp_id,age,sex)
  35.     print(str %args)
  36.     try:
  37.         cur.execute(str %args)
  38.         mydb.commit()
  39.         print("TABLE INSERTED........... n")
  40.         cur.execute("select * from employe")
  41.         row=cur.fetchall()
  42.         while row is not None:
  43.             print(row)
  44.             row=cur.fetchone()
  45.     except Exception as e:
  46.         print(e)
  47.     finally:
  48.         cur.close()
  49.         mydb.close()
  50.  
  51. n=int(input("enter your number: n"))
  52. for i in range(n):
  53.     x=input("enter your first name: n")
  54.     y=input("enter your last name: n")
  55.     z=int(input("enter empp_id: n"))
  56.     a=int(input("enter age: n"))
  57.     b=input("enter sex: n")
  58.  
  59. insertdy(x,y,z,a,b)
  60. import mysql.connector as db
  61. def update(eno):
  62.     mydb=db.connect(host='localhost',
  63.                 user="root",
  64.                 passwd='',
  65.                 database="manthan")
  66.     if mydb:
  67.         print
  68.         print("connection succesful")
  69.     else:
  70.         print("connections failed")
  71.     cur=mydb.cursor()
  72.     str='update employe set sex="M" where emp_id="%d"'
  73.     args=eno
  74.     print(str %args)
  75.     try:
  76.         cur.execute(str %args)
  77.         mydb.commit()
  78.         print("TABLE INSERTED........... n")
  79.  
  80.     except Exception as e:
  81.         print(e)
  82.     finally:
  83.         cur.close()
  84.         mydb.close()
  85. n=int(input("enter the employee number where you want to change: n"))
  86. update(n)
  87. import mysql.connector as db
  88. def update(eno):
  89.     mydb=db.connect(host='localhost',
  90.                 user="root",
  91.                 passwd='',
  92.                 database="ritika")
  93.     if mydb:
  94.         print
  95.         print("connection succesful")
  96.     else:
  97.         print("connections failed")
  98.     cur=mydb.cursor()
  99.     str='delete from employe where emp_id="%d"'
  100.     args=eno
  101.     print(str %args)
  102.     try:
  103.         cur.execute(str %args)
  104.         mydb.commit()
  105.         print("TABLE INSERTED........... n")
  106.  
  107.     except Exception as e:
  108.         print(e)
  109.     finally:
  110.         cur.close()
  111.         mydb.close()
  112. n=int(input("enter the employee number where you want to delete: n"))
  113. update(n)
  114. ?>
Parsed in 0.071 seconds