MySQL SELECT Query in Python with WHERE to get matching records by user input & parameterized query

preview_player
Показать описание

All Video tutorials on MySQL Python in Anaconda Environment

First we will connect to MySQL database by using SQLAlchemy connection engine. With this connection we will collect data from MySQL database.
Here is a sample query to collect all records where class is Four
SELECT * FROM student WHERE class=’Four’
q="SELECT * FROM student WHERE class='Four'"
try:
for row in my_data:
print(row)
except SQLAlchemyError as e:
error=str(e.__dict__['orig'])
print(error)
except Exception as e:
print(e)
else:
We used fetchall() to get all matching records from the table
Getting single record from MySQL database,
Query is here
SELECT * FROM student WHERE id=4
This will return us single record from our sample student table.
We can ask user to input the id of the student and we can display all details of the matching record.
Let us try the query to get the record but we will use parameterized query to pass input value ( id here ) to mysql database to get matching record.
Рекомендации по теме
Комментарии
Автор

Thanks for the video! It helped answer my input variable question.

troybuschbom
join shbcf.ru