Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pymysql.cursors
- #import mysql.connector
- #from mysql.connector import Error
- class db_connection:
- conn = ""
- def __init__(self):
- #If using mysql driver
- #self.conn = mysql.connector.connect(host='192.168.20.248',
- #database='ow2mte',
- #user='root',
- #password='p!tmis88!')
- #If using pymysql driver
- self.conn = pymysql.connect(host='192.168.20.248',
- user='root',
- password='p!tmis88!',
- db='ow2mte',
- charset='utf8mb4',
- cursorclass=pymysql.cursors.DictCursor)
- def check_validity(self, stmt, params):
- cursor = self.conn.cursor()
- query = stmt
- cursor.execute(query, (params,))
- count = cursor.rowcount
- return count
- def disconnect(self):
- self.conn.close()
- def inputNumber(message):
- while True:
- try:
- userEntry = int(input(message))
- return userEntry
- except ValueError:
- break
- #MAIN CODE GOES AFTER THIS LINE
- while True:
- userInput = inputNumber("Please enter your user index: ")
- if userInput:
- try:
- user_access = db_connection()
- is_valid = user_access.check_validity("Select ip_address From login_log Where user_index=%s Limit 0, 1", userInput)
- if is_valid > 0:
- print("It was a valid entry")
- else:
- print("Record not Found!")
- user_access.disconnect()
- except Error as e:
- continue
- elif userInput == 0000:
- break
- else:
- print("Empty/Invalid Entry! Please try again!")
Add Comment
Please, Sign In to add comment