SoftTesting/案例4.py
2025-04-14 23:37:02 +08:00

22 lines
508 B
Python

import pymysql
db=pymysql.connect (
host='localhost',
user='root',
passwd='114514',
database='TESTDB',
)
cursor=db.cursor()
sql="SELECT * FROM EMPLOYEE WHERE INCOME > %s" % 1000
try:
cursor.execute(sql)
result=cursor.fetchall()
for row in result:
fname=row[0]
lname=row[1]
age=row[2]
sex=row[3]
income=row[4]
print(f"fname={fname},lname={lname},age={age},income={income}")
except:
print("Error: unable to fetch data")
db.close()