-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.py
More file actions
30 lines (22 loc) · 861 Bytes
/
database.py
File metadata and controls
30 lines (22 loc) · 861 Bytes
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
29
30
import pymysql.cursors
# Connect to the database
connection = pymysql.connect(host='mrbartucz.com',
user='CS485',
password='WinonaState',
db='CS485',
charset='utf8mb4',
cursorclass=pymysql.cursors.DictCursor)
try:
with connection.cursor() as cursor:
# Select all Students
sql = "SELECT * from Students"
# execute the SQL command
cursor.execute(sql)
# get the results
for result in cursor:
print (result)
# If you INSERT, UPDATE or CREATE, the connection is not autocommit by default.
# So you must commit to save your changes.
# connection.commit()
finally:
connection.close()