-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDB.py
More file actions
53 lines (44 loc) · 1.47 KB
/
DB.py
File metadata and controls
53 lines (44 loc) · 1.47 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
42
43
44
45
46
47
48
49
50
51
52
from secret import bdd_login, bdd_password
#PRE REQUIS
#Avoir installer my sql connector
#Pour faire ca, allez dans cmd et tapez "pip install mysql-connector-python"
#Et ensuite on l'importe dans la ligne d'en dessous
import mysql.connector
from mysql.connector import Error
from mysql.connector import errorcode
class DB:
def __init__():
pass
def ConnexionSQLSelect(requete):
madb = mysql.connector.connect(
host = "localhost",
user = bdd_login,
passwd = bdd_password,
database = "projetpython"
)
#madb = ma database
moncurseur = madb.cursor()
moncurseur.execute(requete)
infos = []
for ligne in moncurseur :
infos.append(ligne)
return infos
def RequestSQL(requete):
try:
madb = mysql.connector.connect(
host = "localhost",
user = bdd_login,
passwd = bdd_password,
database = "projetpython"
)
moncurseur = madb.cursor()
moncurseur.execute(requete)
madb.commit()
print(moncurseur.rowcount, "tuple à bien été pris en compte")
moncurseur.close()
except mysql.connector.Error as error:
print("La requete a echoue {}".format(error))
finally:
if (madb.is_connected()):
madb.close()
print("La connexion MYSQL est fermé")