文章标题
2015-10-14 20:02
423 查看
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()
相关文章推荐
- 【开篇.流水账.反思】从今天开始记录我的学习生涯
- PostgreSQL function's SECURITY DEFINER | INVOKER, SET configuration_parameter { TO value | = value |
- 数字流的使用
- free(): invalid next size (fast/normal)问题
- pylucene在python2.7下的安装
- 重新格式化hadoop
- 【c++程序】虚函数的本质
- 使用字符流的方式进行文件的读取并打印至控制台
- 洛谷 U1406 game
- Android判断软键盘弹出并隐藏的简单完美解决方案
- hadoop2 中log4j日志详解及自定义
- 详解定位以及布局冲突问题
- .NET 开发误区
- 【c++程序】 多态与虚函数
- Android-动画
- centos7 减少/home分区空间,扩大/ 的空间
- 学习一篇关于MMSE的语音信号增强的算法
- IDEA中使用Hibernate数据库框架指导
- CXXFLAGS="-fPIC" && cmake
- 云时代,我们需要PostgreSQL,需要服务端编程