-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.py
More file actions
45 lines (31 loc) · 825 Bytes
/
database.py
File metadata and controls
45 lines (31 loc) · 825 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
41
42
43
44
45
import mysql.connector
import os
from dotenv import load_dotenv
#------------------------------------------------
# Load environment variables
load_dotenv()
# Get DB details from .env file
DB_HOST = os.getenv("HOST")
DB_USER = os.getenv("USER")
DB_PASSWORD = os.getenv("PASSWORD")
DB_NAME = os.getenv("DATABASE")
#------------------------------------------------
# Create DB connection
db = mysql.connector.connect(
host=DB_HOST,
user=DB_USER,
password=DB_PASSWORD,
database=DB_NAME
)
# Cursor to run SQL
cursor = db.cursor()
import mysql.connector
# Connect to MySQL database
db = mysql.connector.connect(
host="localhost",
user="root",
password="Anupam@25",
database="testdb"
)
# Create cursor to run SQL queries
cursor = db.cursor()