Mysql class works like php

Bruno Desthuilliers bruno.42.desthuilliers at wtf.websiteburo.oops.com
Sun Oct 7 08:40:38 EDT 2007


gardsted a écrit :
> Bruno Desthuilliers wrote:
>> Andrey a écrit :
>>> Hi
>>>
>>> just a quick question about using MySQL module... are there any api / 
>>> class available to give a higher level in working with Mysql in python?
>>> such as
>>> db.fetch_array(),
>>> db.fetch_rows(),
>>> db.query(),
>>> for eachrow in db.fetch_array():
>>>     xxxx
>>
(snip)
> Maybe You should look into sqlalchemy.
> I am also a newbie at that, but it allows you to do things like this 
> (untested):
>             sqltxt="""select * from mytable"""
>             result=mysession.execute(sqltxt)
>             for r in result.fetchmany():
> 
> which pretty good mimics the 'for eachrow in db.fetch_array():'

SQLAlchemy is quite a good package (and *way* higher level than anything 
in PHP), but you don't need it to do the above. Any db-api compliant 
package will do:

sql = "SELECT * FROM yaddayadda"
cursor.execute(sql)
for row in cursor.fetchall():
    # code here




More information about the Python-list mailing list