We have built a series a forms using PHP that populate a MySQL Database and after learning more Python want to begin transitioning our whole web app over to a python back end instead of PHP. Can anyone offer a quick intro into searching a MySQL DB using Python?
Asked
Active
Viewed 288 times
2 Answers
0
The easiest way is to abstract the database using an ORM. I found that the python package SQLAlchemy works fantastically.
A ORM let's you treat the database objects as normal python objects. Most queries can be abstracted and for 99% of cases you won't need to write SQL queries. Also this makes transition between database technologies very simple.
Go check it out on:
A search query would be something like:
session.query(User).filter_by(first_name='bob')
Now you will have all users with the first name 'bob'

cchristelis
- 1,985
- 1
- 13
- 17
-
does SQLalchemy work with 2.7.3? I notice the brackets and am curious if that is the syntax for python 3+ – mcclaskiem May 22 '14 at 18:50
-
@mcclaskiem, yes I used it in a 2.7 project. – cchristelis May 22 '14 at 20:24
0
You search it the same way you would in PHP; because the queries you are using will not change.
The only difference is the driver you have to use.

Burhan Khalid
- 169,990
- 18
- 245
- 284