-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmediumdb.py
More file actions
40 lines (30 loc) · 845 Bytes
/
mediumdb.py
File metadata and controls
40 lines (30 loc) · 845 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
31
32
33
34
35
36
37
38
39
40
import mysql.connector
class MediumDB():
def __init__(self):
pass
def writetodb(self):
# Config
config = {
'user': '',
'password': '',
'host': 'localhost',
'database': 'mediumtutorialdb',
'port': 3306,
'raise_on_warnings': True,
}
# Connect to DB
conn = mysql.connector.connect(**config)
# Create Cursor
c = conn.cursor()
# Query
query = (f"INSERT INTO `mediumtutorialdb`.`mediumtable` (`Name`, `Age`) VALUES ('Darryl See', '21')")
# Execute
c.execute(query)
# Commit
conn.commit()
# End Session
c.close()
conn.close()
print('Sent To DB!\n')
x = MediumDB()
x.writetodb()