ImportBinasciiImportOSImportLinecacheImport Time#Add pydes Path#sys.path.append ("/data1/wwwroot")ImportPydesImportStatconfigImportMySQLdbclassmysqlhelper: _conn=Nonedef __init__(self,confdic=None):if notConfdic:confdic=statconfig.conn_dic Self._conn=mysqldb.connect (host=confdic["Host"],user=confdic["User"],passwd=confdic["pwd"],db=confdic["DB"],charset="UTF8") defClose (self): Self._conn.close ()defexecutenonequery (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 ()returnNdefQuery (self,sql,param): cmd=self._conn.cursor () n=Cmd.execute (sql,param) rows=Cmd.fetchall () cmd.close ( )returnRows
A very simple operation of the class, can use it, haha
Python MySQL operation small class, for everyone to use