python怎么把查询结果输出出来

2024-12-27 23:15:47
推荐回答(1个)
回答1:

试试这个fetchone函数
conn=MySQLdb.connect(host='localhost',user='root',passwd='root',db='test',port=3306)
cur=conn.cursor()
cur.execute('select * from user')
data = cur.fetchone()
print "Database : %s " % data
conn.commit()
cur.close()
conn.close()