-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconnect.py
More file actions
38 lines (29 loc) · 890 Bytes
/
Copy pathconnect.py
File metadata and controls
38 lines (29 loc) · 890 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
import mariadb
import sys
# Connect to MariaDB Platform
try:
conn = mariadb.connect(
user="root",
password="flextheplexMaria10!",
host="10.0.0.147",
port=3307, #3306
database="jason_demo"
)
except mariadb.Error as e:
print(f"Error connecting to MariaDB Platform: {e}")
sys.exit(1)
# Get Cursor
cur = conn.cursor()
#retrieving information
some_name = "Jason"
cur.execute("SELECT first_name,last_name FROM family_members WHERE first_name=?", (some_name,))
for first_name, last_name in cur:
print(f"First name: {first_name}, Last name: {last_name}")
# #insert information
# try:
# cur.execute("INSERT INTO employees (first_name,last_name) VALUES (?, ?)", ("Maria","DB"))
# except mariadb.Error as e:
# print(f"Error: {e}")
# conn.commit()
# print(f"Last Inserted ID: {cur.lastrowid}")
conn.close()