ASdfkkdkdoeoosmns PDF
ASdfkkdkdoeoosmns PDF
Program 32: Write the code in python to satisfy the following statements:
(i) Import the desired library to connect with database.
Note the following to establish connectivity between Python and MySQL:
• Host is localhost
• Username is root
• Password is 1234
(ii) Create a database SHGS if not available and connect with it.
(iii) Create a table if not exists in a MySQL database named EMPLOYEE.
• The details (E_CODE, E_NAME, SALARY, CITY) are the attributes of the table:
E_CODE - String
E_NAME - String
SALARY - Integer
CITY - String
(iv) Display the structure of the created table EMPLOYEE.
(v) Make changes permanently in the database.
'''
Design a Python application to obtain a search criteria from user and then fetch
records based on that from EMPLOYEE table..
'''
try:
# Getting the search criteria from user
search_criteria = input("Enter Search Criteria : ")
if result == [] :
print ("No Result Found")
else:
# Print each tuple (row) by using a loop
for i in result:
print (i)
except:
print ("Try Again")
# Search Records
def search(term):
query = "SELECT * FROM CUSTOMER {}".format(term)
cursor.execute(query)
result = cursor.fetchall();
rec = cursor.rowcount
print("Record Found = ", rec, "\n")
for row in result:
print("Customer ID:", row[0])
print("Customer Name:", row[1])
print("Customer Phone:", row[2])
print("Customer City:", row[3])
print("==========================")
if (choice == '1'):
# Inserting New Data
insert()
elif choice == '2':
# Display all Records
search("")
elif choice == '3':
# Delete User Data
delete()
elif choice == '4':
# Update Existing User Data by C_ID
update()
elif choice == '5':
conn.close()
break
else:
print("Invalid Choice! Please Try Again....")
except:
print("Invalid Details! Please Try Again....")
main()
main()