Guest User

Untitled

a guest
Apr 8th, 2018
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. import psycopg2
  2.  
  3. dbname = "WEB02"
  4. username = "postgres"
  5. pwname = ""
  6.  
  7.  
  8. class DB:
  9. def __init__(self):
  10. self.condb()
  11.  
  12. def __del__(self):
  13. self.clodb()
  14.  
  15. def condb(self):
  16. self.connectDB = psycopg2.connect(database=dbname,user=username,password=pwname)
  17. self.cur = self.connectDB.cursor()
  18.  
  19. def selCategories(self):
  20. self.cur.execute("SELECT * FROM categories")
  21. return self.cur.fetchall()
  22.  
  23. def insCategories(self, value):
  24. self.cur.execute("INSERT INTO categories (name) VALUES ('"+value+"')")
  25.  
  26.  
  27. def clodb(self):
  28. self.connectDB.close()
Add Comment
Please, Sign In to add comment