from sqlalchemy import create_engine
from sqlalchemy.exc import SQLAlchemyError
db_file='G:\\My drive\\testing\\my_db.db'
try:
file1='sqlite:///'+ db_file
my_conn = create_engine(file1)
# For MySQL use the below line and remove the above lines for SQLite file
#my_conn = create_engine("mysql+mysqldb://root:pw@localhost/my_tutorial")
r_set=my_conn.execute("SELECT * FROM student WHERE id =6")
data=r_set.fetchone()
except SQLAlchemyError as e:
error = str(e.__dict__['orig'])
print(error)
main.py
Author
🎥 Join me live on YouTubePassionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.