import binascii import os import linecache import time #add pyDes path #sys.path.append("/data1/wwwroot") import pyDes import statConfig import MySQLdb class mysqlHelper: _conn=None def __init__(self,confdic=None): if not confdic: confdic=statConfig.CONN_Dic self._conn=MySQLdb.connect(host=confdic["host"],user=confdic["user"],passwd=confdic["pwd"],db=confdic["db"],charset="utf8") def close(self): self._conn.close() def ExecuteNoneQuery(self,sql,param): #sql = "insert into user(name,created) values(%s,%s)" #param = ("aaa",int(time.time())) cmd = self._conn.cursor() n = cmd.execute(sql,param) self._conn.commit() cmd.close() return n def Query(self,sql,param): cmd = self._conn.cursor() n = cmd.execute(sql,param) rows = cmd.fetchall() cmd.close() return rows
很简的一个操作类,能用就用吧,哈哈