Spaces:
Sleeping
Sleeping
Download connectDatabase.py from Hoanha2101/FPTCheckInFastAPI: direct link, hf CLI and curl.
- Browser
- Download file 895 Bytes
-
https://huggingface.co/spaces/Hoanha2101/FPTCheckInFastAPI/resolve/main/connectDatabase.py
- Command line
-
hf download hf://spaces/Hoanha2101/FPTCheckInFastAPI/connectDatabase.py
-
curl -L -o connectDatabase.py https://huggingface.co/spaces/Hoanha2101/FPTCheckInFastAPI/resolve/main/connectDatabase.py
895 Bytes
| # import pyodbc | |
| # # Thông tin kết nối | |
| # server = 'localhost' # hoặc tên server, ví dụ: 'DESKTOP-ABC123\SQLEXPRESS' | |
| # database = 'CheckInApp' | |
| # username = 'DESKTOP-2G35RJS\SQLEXPRESS' # tên đăng nhập SQL Server | |
| # password = 'matkhaucuaban' | |
| # driver = '{ODBC Driver 17 for SQL Server}' # kiểm tra driver bạn có | |
| # # Tạo kết nối | |
| # conn = pyodbc.connect( | |
| # f'DRIVER={driver};SERVER={server};DATABASE={database};Trusted_Connection=yes;' | |
| # ) | |
| # cursor = conn.cursor() | |
| import psycopg2 | |
| from dotenv import load_dotenv | |
| import os | |
| # Load .env only once | |
| load_dotenv() | |
| USER = os.getenv("user") | |
| PASSWORD = os.getenv("password") | |
| HOST = os.getenv("host") | |
| PORT = os.getenv("port") | |
| DBNAME = os.getenv("dbname") | |
| def get_connection(): | |
| return psycopg2.connect( | |
| user=USER, | |
| password=PASSWORD, | |
| host=HOST, | |
| port=PORT, | |
| dbname=DBNAME | |
| ) |