-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb.py
More file actions
41 lines (33 loc) · 1.12 KB
/
Copy pathdb.py
File metadata and controls
41 lines (33 loc) · 1.12 KB
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
33
34
35
36
37
38
39
40
41
from flask import Flask
import pymysql
class Database:
def __init__(self):
self.user = 'root'
self.password = ''
self.db = 'driving'
self.host = '127.0.0.1'
# con = pymysql.connect(host=host, user=user, password=password, db=db_name, cursorclass=pymysql.cursors.
# DictCursor)
# cur = con.cursor()
def __connect__(self):
self.con = pymysql.connect(host=self.host, user=self.user, password=self.password, db=self.db, cursorclass=pymysql.cursors.
DictCursor)
self.cur = self.con.cursor()
def __disconnect__(self):
self.con.close()
def fetchall(self, sql):
self.__connect__()
self.cur.execute(sql)
result = self.cur.fetchall()
self.__disconnect__()
return result
def fetch(self, sql):
self.__connect__()
self.cur.execute(sql)
result = self.cur.fetchone()
self.__disconnect__()
return result
def execute(self, sql):
self.__connect__()
self.cur.execute(sql)
self.__disconnect__()