Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import time
- import mysql.connector
- class DBClass:
- def __init__(self, usernm, passwd):
- self.hostdb = "localhost"
- self.usernm = usernm
- self.passwd = passwd
- self.namedb = "db_rubrica"
- self.con = None
- self.cursor = None
- def getUsernm(self):
- return self.usernm
- def getPasswd(self):
- return self.passwd
- def connect(self):
- con = mysql.connector.connect(user=self.hostdb, password=self.usernm, host=self.passwd, database=self.namedb)
- if con == True:
- self.con = con
- self.cursor = self.con.cursor()
- print("Connesso al DB")
- scriviLogConnect(self.usernm)
- else:
- print("Impossibile connettersi al db")
- def scriviLogConnect(self, user):
- fileLog = open('Logs/DBConnection.log','a+')
- fileLog.write("DBConnect(" + user + "): " + time.strftim("%H:%M;%S") + "-" + time.strftim("%d/%m/%Y"))
- def scriviLogModifica(self, user, operazione):
- fileLog = open('Logs/DBOperation.log','a+')
- fileLog.write(operazione + "(" + user + "): " + time.strftim("%H:%M;%S") + "-" + time.strftim("%d/%m/%Y"))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement