from DBUtils.PooledDB import PooledDB
import MySQLdb
from log import log_error</code>

def queryDB(pool, SQL):
try:
conn=pool.connection()
cur = conn.cursor()
r = cur.execute(SQL)
r = cur.fetchall()
cur.close()
conn.commit()
conn.close()
return list(r)
except:
log_error('mysql pool error')

调用:

pool_post_json = PooledDB(MySQLdb, 5, host='127.0.0.1', user='root', passwd='123456', db='post_json', port=3306)
json_save_sql=‘selet 1 from dual;’
queryDB(pool_post_json,json_save_sql)

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注

Captcha Code