-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodel.py
41 lines (33 loc) · 1.09 KB
/
model.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
33
34
35
36
37
38
39
40
41
import mysql.connector
class Model( ):
def __init__( self ):
pass
def connection(self):
try:
self.connection = mysql.connector.connect(host=self.Host_Name,user=self.User_Name,password=self.Password,database=self.Database_Name)
self.cursor = self.connection.cursor()
except mysql.connector.Error as e:
return e
def close(self):
self.connection.close()
self.cursor.close()
def execute_sql(self, sql, database):
try:
self.connection = mysql.connector.connect(host=self.Host_Name,user=self.User_Name,password=self.Password,database=database)
self.cursor = self.connection.cursor()
self.cursor.execute(sql)
r = self.connection.commit()
self.close()
return r
except mysql.connector.Error as e:
return e
def return_data(self,sql,database=''):
try:
self.connection = mysql.connector.connect(host=self.Host_Name,user=self.User_Name,password=self.Password, database=database)
self.cursor = self.connection.cursor()
self.cursor.execute(sql)
data = self.cursor.fetchall()
self.close()
return data
except mysql.connector.Error as e:
return e