-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.py
27 lines (22 loc) · 873 Bytes
/
db.py
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
import mysql.connector
class db:
def __init__(self, query):
try:
cnx = mysql.connector.connect(user='root',
password='',
database='real link')
except mysql.connector.Error as err:
if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:
print("Something is wrong with your user name or password")
elif err.errno == errorcode.ER_BAD_DB_ERROR:
print("Database does not exist")
else:
print(err)
else:
cursor = cnx.cursor()
cursor.execute(query)
for (id, jobID, sentence) in cursor:
print("{}, {}, {}".format(
jobID, id, sentence))
cursor.close()
cnx.close()