1 Star 1 Fork 107

Fartimer / flask-ansible

forked from sjgops / flask-ansible 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
tool_db.py 1.52 KB
一键复制 编辑 原始数据 按行查看 历史
shijiange 提交于 2019-07-10 10:10 . first commit
import pymysql,yaml
def getConnect():
try:
with open('config.yml', 'r') as f:
result = yaml.load(f, Loader=yaml.FullLoader)
mysqlresult = result['mysql']
connect = pymysql.connect(mysqlresult['host'], mysqlresult['username'], mysqlresult['password'], mysqlresult['database'], mysqlresult['port'])
return connect
except Exception as e:
print( e )
def selectByParameters( sql, params = None ):
try:
connect = getConnect()
cursor = connect.cursor( pymysql.cursors.DictCursor )
cursor.execute( sql, params )
result = cursor.fetchall()
return result
except Exception as e:
print( e )
finally:
try:
cursor.close()
except Exception as e:
print(e)
try:
connect.close()
except Exception as e:
print(e)
def updateByParameters( sql, params = None ):
try:
connect = getConnect()
cursor = connect.cursor( pymysql.cursors.DictCursor )
count = cursor.execute( sql, params )
connect.commit()
return count
except Exception as e:
connect.rollback()
print( e )
finally:
try:
cursor.close()
except Exception as e:
print(e)
try:
connect.close()
except Exception as e:
print(e)
if __name__ == "__main__":
sql = "delete from servers where id = %s"
result = updateByParameters(sql, params=( 3, ))
print( result )
Python
1
https://gitee.com/farTrue/flask-ansible.git
git@gitee.com:farTrue/flask-ansible.git
farTrue
flask-ansible
flask-ansible
master

搜索帮助