-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase_.py
More file actions
28 lines (25 loc) · 1.06 KB
/
Copy pathdatabase_.py
File metadata and controls
28 lines (25 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import mysql.connector as mysql
#rootpass123
# DATABASE: accounts, TABLE: users
class database(object):
def __init__(self, host, user, user_pass, database_name):
self.host, self.database_name = host, database_name
self.user, self.user_pass = user, user_pass
try:
self.datab = mysql.connect(
host=host,
user=user,
passwd=user_pass,
database=database_name)
self.cursor = self.datab.cursor()
except mysql.Error as err:
print('Something went wrong:\n{}'.format(err))
def check_val_incol(self, val, col, table):
self.cursor.execute("SELECT {} FROM {} where {} = '{}' LIMIT 1".format(col,
table,
col,
val))
if self.cursor.fetchone():
return True
else:
return False