0996 HKK
0996 HKK
Done By:
Name: Hamza Khan
Reg. No:
CERTIFICATE
Principal
ACKNOWLEDGEMENT
Sr NO Name Page
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.
import sys
def menu():
loop='y'
while(loop=='y' or loop=='Y'):
print("........MENU.......")
print()
print()
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.")
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()
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()
cur.execute(query1)
con.commit()
print('Record Inserted')
con.close()
else:
def update_record():
con=driver.connect(host='localhost',user='root',passwd='hamzaA123',database='employee')
cur=con.cursor()
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 : "))
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()
if choice==1:
elif choice==2:
elif choice==3:
else:
print("Wrong Choice")
cur.execute(query1)
rec=cur.fetchall()
count=cur.rowcount
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()
rec=cur.fetchall()
count=cur.rowcount
print("+----------|--------------|-----------+")
print("+----------|--------------|-----------+")
for i in rec:
print("+----------|--------------|-----------+")
print("+-------------------------------------+")
for i in rec:
print(i)
con.close()
else:
menu()
Outputs:
1. Menu
2. Creation of database
5. Insertion of data
7. Updating of data
8. Searching the data
9. Deletion of data
References
www.stackoverflow.com
www.learnpython.org
www.geeksforgeeks.org
Computer Science Grade 12 CBSE Textbook (Sumita
Arora)