码迷,mamicode.com
首页 > 数据库 > 详细

mysql module_class_excute

时间:2016-03-07 18:55:14      阅读:190      评论:0      收藏:0      [点我收藏+]

标签:

#!/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‘)




 

mysql module_class_excute

标签:

原文地址:http://www.cnblogs.com/fengjian2016/p/5251188.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!