简体   繁体   中英

Searching a MySQL Database on ClearDB using Python script

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?

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:

http://www.sqlalchemy.org/

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'

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM