import MySQLdb
class Mysql_api:
def __init__(self,database_name,username="root",password="******"):
try:
self.con=MySQLdb.connect(host="localhost",user=username,passwd=password,db=database_name)
self.cursor=self.con.cursor()
except Exception,e:
print e
def execute(self,*sql):
try:
if len(sql)>1:
for sqlchild in sql:
self.cursor.execute(sqlchild)
else:
self.cursor.execute(sql[0])
except Exception,e:
print e
def fetch(self):
try:
result_man=[]
result=self.cursor.fetchall()
if result:
if isinstance(result[0][0],long):
result_man=list(result)
else:
zip_result=zip(*result)[0]
result_man=list(zip_result)
except Exception,e:
print e,
return result_man
def close(self):
self.cursor.close()
self.con.close()
self.con.close()
文章标题
最新推荐文章于 2024-04-22 16:59:44 发布
部署运行你感兴趣的模型镜像
您可能感兴趣的与本文相关的镜像
Python3.10
Conda
Python
Python 是一种高级、解释型、通用的编程语言,以其简洁易读的语法而闻名,适用于广泛的应用,包括Web开发、数据分析、人工智能和自动化脚本
2560

被折叠的 条评论
为什么被折叠?



