python2 下 DBUtils安装与使用
python -m pip install DBUtils==2.0.3
DButils版本:
from versions: 0.8.1, 0.9.1, 0.9.2, 0.9.3, 0.9.4, 1.0, 1.1, 1.1.1, 1.2, 1.3, 1.4, 2.0, 2.0.1, 2.0.2, 2.0.3, 3.0.0, 3.0.1, 3.0.2
from dbutils.pooled_db import PooledDB
def doSql():
sql = 'insert into LyicTable (a,aa,aaa,aaaa,aaaaa) values(%s,%s,%s,%s,%s)'
conn = POOL.connection()
cursor = conn.cursor()
try:
cursor.execute(sql, (a,aa,aaa,aaaa,aaaaa))
conn.commit()
print ({'result': True, 'id': int(cursor.lastrowid)})
except Exception as e:
conn.rollback()
print ({'result':False, 'sql error is :':e})
finally:
cursor.close()
conn.close()