import pymysql db=pymysql.connect("localhost","root","","paoding",charset='utf8') cursor=db.cursor() # cursor.execute('SET NAMES UTF8') sql="select *from userdata" try: cursor.execute(sql) results=cursor.fetchall() for row in results: id=row[0] phone=row[1] password=row[2] user_name=row[3] # print("id:"+id+" phone:"+phone+" password:"+password+" user_name:"+user_name) print("id:"+id+" phone:"+phone+" password:"+password+" user_name:"+user_name+" ") except: print("Error :unable to fetch data") pass db.close()
Python连接数据库
最新推荐文章于 2021-03-01 15:33:38 发布