-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.py
32 lines (24 loc) · 937 Bytes
/
db.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# coding:utf-8
import pymysql
class DB(object):
def __init__(self, host,port, user, password, dbname, charset='utf-8'):
if host is None or user is None or password is None or dbname is None:
return None
self.conn = pymysql.connect(host=host, port=port, user=user, passwd=password, db=dbname, charset=charset)
self.cur = self.conn.cursor(pymysql.cursors.DictCursor)
# self.cur.execute("select version()")
#
# for i in self.cur:
# print(i)
# self.cur.close()
def execute(self, sql, params):
self.cur.execute(sql, params)
self.conn.commit()
return self.cur.lastrowid
def executemany(self, sql, params):
self.cur.executemany(sql, params)
self.conn.commit()
return self.cur.lastrowid
def select(self, sql, param=None):
self.cur.execute(sql,param)
return self.cur.fetchall()