1 Star 0 Fork 106

equalll/flask-ansible

forked from sjgops/flask-ansible 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
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 )
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/forgo/flask-ansible.git
git@gitee.com:forgo/flask-ansible.git
forgo
flask-ansible
flask-ansible
master

搜索帮助