Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time, sys
- import mysql.connector
- from mysql.connector import errorcode
- class dbCalls(object):
- def __init__(self, dbName, table_Name):
- self.dbName = dbName
- self.tableName = table_Name
- # print(dbName) # for testing/debugging
- # print(table_Name) # for testing/debugging
- try:
- cnx = mysql.connector.connect(user='root', password='xxxxxxx', host='127.0.0.1',
- database='IAM_Framework')
- except mysql.connector.Error as err:
- if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:
- print("Something is wrong with the username or password")
- elif err.errno == errorcode.ER_BAD_DB_ERROR:
- print("Database does not exist")
- else:
- print(err)
- else:
- cursor = cnx.cursor()
- # print(cnx)
- def queryDB(self, table_Name):
- cursor.execute('SELECT * FROM ' + table_Name)
- for result in cursor:
- print(result)
- cnx.close()
- def insertIntoTable(self, table_name, *args):
- pass
- def updateTable(self, table_name, *args):
- pass
- def deleteFromTable(self, table_name, *args):
- pass
- # main calls; still developing and testing :)
- table_Name ='departments'
- action = dbCalls('IAM_Framework', 'employees')
- action.queryDB(table_Name)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement