导入DBUtils报错
降低版本
pip install DBUtils==1.3
参考:
数据库连接DBUtils.PooledDB 安装失败【Flask】_来杯Sherry的博客-CSDN博客
创建连接:
mysql方式
class SqlHelper(object): def __init__(self): self.pool = PooledDB( creator=pymysql, maxconnections=6, mincached=2, blocking=True, ping=0, host='127.0.0.1', port=3306, user='root', password='*******', database='数据库名', ) def open(self): conn = self.pool.connection() cursor = conn.cursor() return conn, cursor def close(self, conn, cursor): conn.close() cursor.close def fetchall(self,sql,*args): # 获取所有数据 conn,cursor=self.open() cursor.execute(sql,args) result = cursor.fetchall() self.close(conn, cursor) return result def fetchallone(self,sql,*args): #获取单个数据 conn,cursor=self.open() cursor.execute(sql,args) result = cursor.fetchone() self.close(conn, cursor) return result db = SqlHelper()
在b站学的
oracle连接:
POOl = PooledDB( creator=cx_Oracle, maxconnections=6, blocking=True, ping=0, dsn='127.0.0.1:3306/数据库名', user='root', password='*******', encoding='utf8' )
参考Python3 PooledDB连接池参数解释以及连接常见数据库操作_pooleddb 参数详解_shawn_wxn的博客-CSDN博