import pymysql as mysql
try:
db=mysql.connect(host="localhost",port=3306,user="root",password='123',db="lg")
cmd=db.cursor()
id=input("Enter Id you Want to Search?")
q="Select * from employee where employeeid={0}".format(id)
cmd.execute(q)
row=cmd.fetchone()
if(row):
print("Employee Name:",row[1])
print("Salary:", row[2])
print("Designation:", row[3])
print("City:", row[4])
print("Birth Date:", row[5])
else:
print("Record Not Found....")
db.close()
except Exception as e:
print(e)
Output:
Enter Id you Want to Search?23
Employee Name:John
Salary:45000
Designation:Senior Developer
City:London
Birth Date:12/4/1988
Program to search for a record using ID in Python
Output:
need an explanation for this answer? contact us directly to get an explanation for this answer