Advertisement
titaniumtitanium

PyClassAndMethod

Feb 6th, 2019
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.18 KB | None | 0 0
  1. import time, sys
  2. import mysql.connector
  3. from mysql.connector import errorcode
  4.  
  5. class dbCalls(object):
  6.     def __init__(self, dbName, table_Name):
  7.         self.dbName = dbName
  8.         self.tableName = table_Name
  9.         # print(dbName) # for testing/debugging
  10.         # print(table_Name) # for testing/debugging
  11.         try:
  12.             cnx = mysql.connector.connect(user='root', password='xxxxxxx', host='127.0.0.1',
  13.                     database='IAM_Framework')
  14.         except mysql.connector.Error as err:
  15.             if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:
  16.                 print("Something is wrong with the username or password")
  17.             elif err.errno == errorcode.ER_BAD_DB_ERROR:
  18.                 print("Database does not exist")
  19.             else:
  20.                 print(err)
  21.         else:
  22.             cursor = cnx.cursor()
  23.             # print(cnx)
  24.  
  25.     def queryDB(self, table_Name):
  26.         cursor.execute('SELECT * FROM ' + table_Name)
  27.         for result in cursor:
  28.             print(result)
  29.  
  30.         cnx.close()
  31.  
  32.     def insertIntoTable(self, table_name, *args):
  33.         pass
  34.  
  35.     def updateTable(self, table_name, *args):
  36.         pass
  37.  
  38.     def deleteFromTable(self, table_name, *args):
  39.         pass
  40.  
  41. # main calls; still developing and testing :)
  42. table_Name ='departments'
  43. action = dbCalls('IAM_Framework', 'employees')
  44. action.queryDB(table_Name)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement