forked from Karolayne-silva/atv-sistemaDeGestaoAcademica
-
Notifications
You must be signed in to change notification settings - Fork 0
/
conexaoDB.py
33 lines (26 loc) · 1005 Bytes
/
conexaoDB.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
import mysql.connector
class ConexaoDB:
def __init__(self, host="localhost", user="root", password="teste", database ="sga"):
self.host = host
self.user = user
self.password = password
self.database = database
def conectar(self):
self.conexao = mysql.connector.connect(host = self.host,
user = self.user,
password = self.password,
database = self.database)
self.cursor = self.conexao.cursor()
def desconectar(self):
self.conexao.close()
def executarDQL(self, comando):
self.conectar()
self.cursor.execute(comando)
resultado = self.cursor.fetchall()
self.desconectar()
return print(resultado)
def executarDML(self, comando):
self.conectar()
self.cursor.execute(comando)
self.conexao.commit()
self.desconectar()