1 Star 0 Fork 3

祝子豪/flask_cmdb

forked from 施超/flask_cmdb 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
mysql_tools.py 1.46 KB
一键复制 编辑 原始数据 按行查看 历史
施超 提交于 2022-06-14 11:51 . no message
#!/usr/bin/env python
# _*_ coding: utf-8 _*_
# Author:shichao
# File: .py
import pymysql
# 封装连接
def getConnect():
try:
connection = pymysql.connect(
host="127.0.0.1",
user="root",
password="123456",
database="flask_cmdb",
port=3306)
return connection
except Exception as e:
print(e)
def selectByParameters(sql, params=None):
try:
connection = getConnect()
cursor = connection.cursor(pymysql.cursors.DictCursor)
cursor.execute(sql,params)
fc = cursor.fetchall()
return fc
except Exception as e:
print(e)
finally:
try:
cursor.close()
except Exception as e:
print(e)
try:
connection.close()
except Exception as e:
print(e)
def updateByParameters(sql, params=None):
try:
connection = getConnect()
cursor = connection.cursor(pymysql.cursors.DictCursor)
count = cursor.execute(sql,params)
connection.commit()
return count
except Exception as e:
connection.rollback()
print(e)
finally:
try:
cursor.close()
except Exception as e:
print(e)
try:
connection.close()
except Exception as e:
print(e)
if __name__ == '__main__':
sql = "select * from servers"
result = selectByParameters( sql )
print(result)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/haoganditian/flask_cmdb.git
[email protected]:haoganditian/flask_cmdb.git
haoganditian
flask_cmdb
flask_cmdb
master

搜索帮助