zoukankan      html  css  js  c++  java
  • MySQLdb模块 类操作方法

    #!/usr/bin/env python
    #-*- coding:utf-8 -*-
    
    from day5 import conf
    import MySQLdb
    
    
    class MysqlHepler(object):
        def __init__(self):
            self.conn = MySQLdb.connect(**conf.conn_dict)
            self.cur = self.conn.cursor(cursorclass=MySQLdb.cursors.DictCursor)
            self.cur.execute(sql,parmas)
    
        def Select_All(self,sql,parmas):
            refetch = self.cur.fetchall()
            self.cur.close()
            self.conn.close()
            return refetch
    
        def Execute(self,sql,parmas):
            self.conn.commit()
            self.cur.close()
            self.conn.close()
    
    
    
    p1 = MysqlHepler()
    sql = 'select * from admin where id = %s'
    parmas = (3,)
    p1.Select_All(sql,parmas)




    #######################################################

    #!/usr/bin/env python
    #-*- coding:utf-8 -*-

    from day5.utility.sql_helpler import MysqlHepler
    import MySQLdb

    class AdminClass(object):
    def __init__(self):
    self.helper = MysqlHepler()

    def SelectIp(self,id):
    sql = 'select * from admin where id = %s'
    parmas = (id,)
    return self.helper.Select_All(sql,parmas)


    #########################################################

    conn_dict = dict(host='172.16.202.182',user='fengjian',passwd='123456',db='fengjian')




  • 相关阅读:
    Nbear讲解 之核心类CodeGenerator
    计算字符串显示的像素
    C# 加密算法[汇总]
    索引器的本质
    Excel[.xls|.xlsx|.csv] 导入 导出
    Spring.Net Ioc 实例
    反射中 BindingFlags标识
    C# 图片操作 常用方法 总结
    iTextSharp 生成pdf Form 实例
    玩转 Route
  • 原文地址:https://www.cnblogs.com/fengjian2016/p/5251188.html
Copyright © 2011-2022 走看看