盒子
盒子
文章目录
  1. 安装
  2. 常规使用

数据库

安装

pip install pymysql

常规使用

import pymysql

# 连接
conn = pymysql.connect(
host=db_info['ip'], user=db_info['user'], passwd=db_info['password'],
port=port, db=db_info['dbname'], charset='utf8')
conn.autocommit(autocommit) # 是否自动提交
cur = conn.cursor()

# 语句执行
cur.execute(sql)
# 事务提交
conn.commit()

# Select 结果
cur.fetchone()
cur.fetchmany(num)
cur.fetchall()

# insert / update / delete 影响个数
cur.rowcount
cur.rownumber
支持一下
扫一扫,支持一下
  • 微信扫一扫
  • 支付宝扫一扫