当前位置:Gxlcms > 数据库问题 > 利用PyMySQL库连接数据库

利用PyMySQL库连接数据库

时间:2021-07-01 10:21:17 帮助过:38人阅读

= pymysql.connect("localhost","root","123456","python") # mysql语句 sql = select item_title,item_image,item_price from tb_cart; #获取游标对象 cursor = db.cursor() #将数据库语句发送给数据库 cursor.execute(sql) #接收数据返回的数据 # 使用 fetchone() 方法获取单条数据,fetchall()获取多条 # data = cursor.fetchall() data = cursor.fetchmany(2) print(cursor.rowcount) print(data) print(len(data)) #用完,关闭连接 #关闭游标 cursor.close() #关闭数据库连接 db.close()

 

利用PyMySQL库连接数据库

标签:一个   pytho   span   price   commit   对象   mysql语句   利用   windows平台   

人气教程排行