import pymysql
db=pymysql.connect(host='localhost',
user='root',
password='Shiyue%120',
db='test',
port=3306,
charset='utf8')
#db= pymysql.connect(host="localhost",user="root",
# password="Shiyue%120",db="test",port=3307)
cursor = db.cursor()
try:
sql='select name from test1 where id = 2'
cursor.execute(sql)
result = cursor.fetchall()
for row in result:
print(row[0])
print(row[1])
print(row[2])
except:
print("er")
网友评论