zoukankan      html  css  js  c++  java
  • sql语句组件 在框架中的应用

    class sqlHandler():
        def __init__(self):
            self.connect()
    
        def connect(self):
            self.conn = conn = pymysql.connect(host="127.0.0.1", port=3306, user="root", passwd="", db="db2")
            self.cursor = conn.cursor(cursor=pymysql.cursors.DictCursor)
    
        def getOne(self,sql,args):
            self.cursor.execute(sql, args)
            result = self.cursor.fetchone()
            return result
    
        def getAll(self,sql,args):
            self.cursor.execute(sql, args)
            result = self.cursor.fetchall()
            return result
    
        def modify(self,sql,args):
            self.cursor.execute(sql,args)
            self.conn.commit()
    
        def modifyMany(self,sql,args):
            self.cursor.executemany(sql,args)
            self.conn.commit()
    
        def close(self):
            self.cursor.close()
            self.conn.close()
    
        def create(self,sql,args):
            self.cursor.execute(sql,args)
            ret = self.cursor.lastrowid
            self.conn.commit()
            return ret
  • 相关阅读:
    每日总结59
    每日总结58
    每日总结57
    每日总结56
    每日总结55
    每日总结54
    每日总结53
    每日总结52
    学习日报
    学习日报
  • 原文地址:https://www.cnblogs.com/hude/p/12526560.html
Copyright © 2011-2022 走看看