Advertisement
Guest User

Untitled

a guest
Jun 16th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.21 KB | None | 0 0
  1. #!/usr/bin/python
  2. import time
  3. import mysql.connector
  4.  
  5. class DBClass:
  6.     def __init__(self, usernm, passwd):
  7.         self.hostdb = "localhost"
  8.         self.usernm = usernm
  9.         self.passwd = passwd
  10.         self.namedb = "db_rubrica"
  11.         self.con    = None
  12.         self.cursor = None
  13.  
  14.     def getUsernm(self):
  15.         return self.usernm
  16.  
  17.     def getPasswd(self):
  18.         return self.passwd
  19.  
  20.     def connect(self):
  21.         con = mysql.connector.connect(user=self.hostdb, password=self.usernm, host=self.passwd, database=self.namedb)
  22.         if con == True:
  23.             self.con = con
  24.             self.cursor = self.con.cursor()
  25.             print("Connesso al DB")
  26.             scriviLogConnect(self.usernm)
  27.  
  28.         else:
  29.             print("Impossibile connettersi al db")
  30.  
  31.     def scriviLogConnect(self, user):
  32.         fileLog = open('Logs/DBConnection.log','a+')
  33.         fileLog.write("DBConnect(" + user + "): " + time.strftim("%H:%M;%S") + "-" + time.strftim("%d/%m/%Y"))
  34.  
  35.     def scriviLogModifica(self, user, operazione):
  36.         fileLog = open('Logs/DBOperation.log','a+')
  37.         fileLog.write(operazione + "(" + user + "): " + time.strftim("%H:%M;%S") + "-" + time.strftim("%d/%m/%Y"))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement