Created
September 20, 2022 14:40
-
-
Save dineshkumarkb/d21da8b3794eb89348eda334bd63a2ae to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from sqlalchemy import create_engine, text | |
| from sqlalchemy.exc import SQLAlchemyError | |
| from sqlalchemy.orm import sessionmaker | |
| from urllib.parse import quote | |
| def connect_to_db(): | |
| connection_url = "mysql+pymysql://<username>:<password>@<hostname>:3306/<databasename>" | |
| try: | |
| engine = create_engine(url=connection_url) | |
| # create a session | |
| session = sessionmaker(bind=engine) | |
| conn = session() | |
| if session: | |
| return conn | |
| except SQLAlchemyError as se: | |
| print(se) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment