python--pymysql模块学习笔记

本文介绍了Python中的pymysql模块,重点讲解了connection和cursor两个核心对象及其方法。connection对象用于建立数据库连接,提供如关闭连接、提交事务等操作;cursor对象则用于执行SQL查询,包括执行单条或多条查询、获取查询结果等。文中还给出了具体的代码示例和使用笔记。
摘要由CSDN通过智能技术生成

一:两个对象 connection 与 cursor

       调用connect()方法创建 connection对象:

connection = pymysql.connect(args)

       connection对象方法与属性介绍:

close()                           Send the quit message and close the socket.
commit()                       Commit changes to stable storage.
cursor(cursor=None)   Create a new cursor to execute queries with.
open                             Return True if the connection is open
begin()                          Begin transaction;
ping(reconnect=True)  Check if the server is alive.
rollback()                      Roll back the current transaction.
select_db(db)               Set current db.

show_warnings()          Send the “SHOW WARNINGS” SQL command

       cursor对象是用来与数据库进行交互的;通过connection对象调用cursor()方法创建cursor对象

cursor = connection.cursor()
# 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值