-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinkdb.py
24 lines (21 loc) · 819 Bytes
/
linkdb.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
import mysql.connector
class dbDataset:
def __init__(self):
#Link to databse
self.mydb = mysql.connector.connect(
host="workshop-1.cgd5y8wpwke1.us-east-1.rds.amazonaws.com",
user="admin",
passwd="82eEzsl5wnuEsX0UG9sZ",
database="heartdisease_schema"
)
def recoverTable(self,table):
mycursor = self.mydb.cursor()
mycursor.execute("SELECT age, sex, cp, trestbps, chol, fbs, restecg, thalach, exang, oldpeak, slope, ca, thal, target FROM " + table)
# Extract headers
columns = [col[0] for col in mycursor.description]
#Generate list of Dict
rows = [dict(zip(columns, row)) for row in mycursor.fetchall()]
return rows
#db = dbDataset()
#myresult = db.recoverTable("dataset")
#print(myresult)