python 模块 DButils

 

# DButils 为了解决多客户端都需要操作数据库的问题.# import pymysql# from DBUtils.PooledDB import PooledDB## POOL = PooledDB(creator=pymysql,# mincached=2,# maxcached=5,# maxshared=3,# maxconnections=6,# blocking=True,# maxusage=None,# ping=4,# host=‘172.16.2.106‘,# port=3306,# user=‘root‘,# password=‘123456‘,# database=‘anec‘,# charset=‘utf8‘# )## coon = POOL.connection()# cursor = coon.cursor(cursor=pymysql.cursors.DictCursor)# info_msg = {# ‘cx‘:‘select * from text where id=1‘,# ‘cr‘:‘insert into text(id,name,phone,enail) values(2,"alex","123123213","123@qewq.com")‘# }# 查询数据# cursor.execute(‘select * from text ‘)# ret = cursor.fetchall()# 增加数据# cursor.execute(‘insert into text(id,name,phone,enail) values(2,"alex","123123213","123@qewq.com")‘)# coon.commit()## 删除一条数据# cursor.execute(‘delete from text where id=2‘)# coon.commit()# 修改数据# cursor.execute(‘update text set phone = 18711068587 where id=1‘)# coon.commit()# cursor.execute(‘select * from text‘)# ret = cursor.fetchall()# coon.close()# print(ret)

 

相关文章