利用Python创建链接mysql数据库个性化对象
2017-09-03 21:38
441 查看
import pymysql class Sql: db = None cursor = None def __init__(self): print('connecting to mysql...') self.db = pymysql.connect("localhost", "root", "root", "edu", charset="utf8") self.cursor = self.db.cursor() print('connected!') def select(self,selectSql): try: results = self.cursor.execute(selectSql) res = self.cursor.fetchmany(results) return res except: print("Select error: unable to fecth data!") def update(self,updateSql): try: self.cursor.execute(updateSql) self.db.commit() except: print("Update error: unable to update data!") def delete(self,deleteSql): try: self.cursor.execute(deleteSql) except: print("Delete error:unable to delete data!") def getCursor(self): return self.cursor def closedb(self): # 关闭数据链接 self.db.close()
相关文章推荐
- 利用Python创建链接mysql数据库个性化对象
- Python利用new创建一个类的对象
- 利用对象的思想创建二叉树并实现四种遍历(广序,先序,中序,后序)-python3版
- Python利用Beautiful Soup模块创建对象详解
- python进阶学习笔记(七)——利用__call__将类转化为可调用的对象
- C#回顾 - 8.利用反射动态创建对象
- Python3.5+Django1.8链接Mysql数据库的方法
- js中利用函数创建对象的5种模式
- java中利用类名生成Class对象,通过class对象创建实体类的理解
- Python——创建更加牛逼的对象
- 利用Python写一个Mysql数据库积压监控
- Python ACCESS学习(二) 创建文件链接ACCESS数据库
- Python编程-数据库-利用PyMysql访问windows下的MySql数据库
- js利用数组创建图片对象
- Python利用operator模块实现对象的多级排序详解
- python_如何创建可管理的对象属性
- Python利用{}.fromkeys来创建空字典的时候要注意附默认值时其他键会同时变化
- Python中链接MySql数据库的配置
- 求圆的周长和面积!利用Scanner创建对象进行数据的输入
- DC学院数据分析师(入门)学习笔记----利用python操作MySQL数据库