该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
拿去抄作业!!!
class My_DB_oms():
def __init__(self):
# OMS 数据库
self.host = '11111'
self.db = '111111'
self.user = '11111'
self.passwd = '1111'
self.conn= self.oms_conn()
def oms_conn(self):
try:
conn = pymssql.connect(self.host, self.user, self.passwd, self.db, charset='utf8', tds_version='7.0')
# print('-- -构造函数- --数据库链接成功!-----')
except Exception as e:
conn =False
print('数据库链接失败!' + e)
return conn
def query_one(self,sql=''):
if sql == None:
print("sql 不能为空!请重试")
return false
else:
conns = self.conn.cursor()
try:
conns.execute(sql)
res = conns.fetchone()
except Exception as e:
print("脚本执行失败!sql: "+sql+"\n"+str(e))
return False
conns.close()
self.conn.close()
return res
def query_all(self, sql=''):
if sql == None:
print("sql 不能为空!请重试")
return false
else:
conn = self.conn.cursor()
try:
res = conn.execute(sql)
result = conn.fetchall()
return result
except Exception as e:
print("脚本执行失败!sql: " + sql + "\n" + str(e))
res.close()
return False
def insert_data(self,sql):
pass
def update_data(self,sql):
if sql == None:
print("sql 不能为空!请重试")
return false
else:
conn = self.conn.cursor()
try:
res = conn.execute(sql)
self.conn.commit()
print('----------self.conn.commit()---------')
return True
except Exception as e:
print("脚本执行失败!sql: " + sql + "\n" + str(e))
res.close()
return False
#res.close()
def __del__(self):
try:
self.conn.close()
# print("--- ---析构函数---- ---"+"关闭数据库链接成功!")
except Exception as e :
print(e)