时间:2021-07-01 10:21:17 帮助过:50人阅读
class Connection(_mysql.connection):
"""MySQL Database Connection Object"""
default_cursor = cursors.Cursor
def __init__(self, *args, **kwargs):
"""
Create a connection to the database. It is strongly recommended
that you only use keyword parameters. Consult the MySQL C API
documentation for more information.
host
string, host to connect
user
string, user to connect as
passwd
string, password to use
db
string, database to use
port
integer, TCP/IP port to connect to
charset
If supplied, the connection character set will be changed
to this character set (MySQL-4.1 and newer). This implies
use_unicode=True.
"""
2 操作数据库:首先需要获得一个cursor对象, 然后使用cursor的方法执行SQL
def execute(self, query, args=None):
"""Execute a query.
query -- string, query to execute on server
args -- optional sequence or mapping, parameters to use with query.
Note: If args is a sequence, then %s must be used as the
parameter placeholder in the query. If a mapping is used,
%(key)s must be used as the placeholder.
Returns long integer rows affected, if any
"""
3 接收返回值:也是使用cursor对象的方法进行接收
4 关闭数据库:需要关闭cursor对象和connect对象
3 Selenium Python 数据库及文件
标签:abs 2.7 margin set *args 2.3 连接数据库 api port